2018-11-11 18:32:48 -05:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package scheduler // import "miniflux.app/service/scheduler"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"miniflux.app/config"
|
|
|
|
"miniflux.app/logger"
|
|
|
|
"miniflux.app/storage"
|
|
|
|
"miniflux.app/worker"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Serve starts the internal scheduler.
|
2019-06-01 21:18:09 -04:00
|
|
|
func Serve(store *storage.Storage, pool *worker.Pool) {
|
2018-11-11 18:54:19 -05:00
|
|
|
logger.Info(`Starting scheduler...`)
|
2019-06-01 21:18:09 -04:00
|
|
|
go feedScheduler(store, pool, config.Opts.PollingFrequency(), config.Opts.BatchSize())
|
|
|
|
go cleanupScheduler(store, config.Opts.CleanupFrequency(), config.Opts.ArchiveReadDays())
|
2018-11-11 18:32:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func feedScheduler(store *storage.Storage, pool *worker.Pool, frequency, batchSize int) {
|
|
|
|
c := time.Tick(time.Duration(frequency) * time.Minute)
|
|
|
|
for range c {
|
|
|
|
jobs, err := store.NewBatch(batchSize)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("[Scheduler:Feed] %v", err)
|
|
|
|
} else {
|
|
|
|
logger.Debug("[Scheduler:Feed] Pushing %d jobs", len(jobs))
|
|
|
|
pool.Push(jobs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 23:35:30 -05:00
|
|
|
func cleanupScheduler(store *storage.Storage, frequency int, archiveDays int) {
|
2018-11-11 18:32:48 -05:00
|
|
|
c := time.Tick(time.Duration(frequency) * time.Hour)
|
|
|
|
for range c {
|
|
|
|
nbSessions := store.CleanOldSessions()
|
|
|
|
nbUserSessions := store.CleanOldUserSessions()
|
|
|
|
logger.Info("[Scheduler:Cleanup] Cleaned %d sessions and %d user sessions", nbSessions, nbUserSessions)
|
|
|
|
|
2018-12-05 23:35:30 -05:00
|
|
|
if err := store.ArchiveEntries(archiveDays); err != nil {
|
2018-11-11 18:32:48 -05:00
|
|
|
logger.Error("[Scheduler:Cleanup] %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|