51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package internal
|
|
|
|
import (
|
|
"github.com/robfig/cron"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// JobSpec ...
|
|
type JobSpec struct {
|
|
Schedule string
|
|
Factory JobFactory
|
|
}
|
|
|
|
func NewJobSpec(schedule string, factory JobFactory) JobSpec {
|
|
return JobSpec{schedule, factory}
|
|
}
|
|
|
|
var (
|
|
Jobs map[string]JobSpec
|
|
StartupJobs map[string]JobSpec
|
|
)
|
|
|
|
func init() {
|
|
Jobs = map[string]JobSpec{
|
|
"SyncStore": NewJobSpec("@every 1m", NewSyncStoreJob),
|
|
}
|
|
|
|
StartupJobs = map[string]JobSpec{}
|
|
}
|
|
|
|
type JobFactory func(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, store Store) cron.Job
|
|
|
|
type SyncStoreJob struct {
|
|
conf *Config
|
|
blogs *BlogsCache
|
|
cache *Cache
|
|
archive Archiver
|
|
db Store
|
|
}
|
|
|
|
func NewSyncStoreJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job {
|
|
return &SyncStoreJob{conf: conf, blogs: blogs, cache: cache, archive: archive, db: db}
|
|
}
|
|
|
|
func (job *SyncStoreJob) Run() {
|
|
if err := job.db.Sync(); err != nil {
|
|
log.WithError(err).Warn("error sycning store")
|
|
}
|
|
log.Info("synced store")
|
|
}
|