2017-11-20 00:10:04 -05:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
package scheduler // import "miniflux.app/scheduler"
|
2017-11-20 00:10:04 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2017-11-22 01:36:00 -05:00
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/logger"
|
|
|
|
"miniflux.app/storage"
|
2017-11-20 00:10:04 -05:00
|
|
|
)
|
|
|
|
|
2017-12-16 21:48:17 -05:00
|
|
|
// NewFeedScheduler starts a new scheduler that push jobs to a pool of workers.
|
|
|
|
func NewFeedScheduler(store *storage.Storage, workerPool *WorkerPool, frequency, batchSize int) {
|
2017-11-22 01:36:00 -05:00
|
|
|
go func() {
|
|
|
|
c := time.Tick(time.Duration(frequency) * time.Minute)
|
2018-03-02 00:31:57 -05:00
|
|
|
for range c {
|
2017-11-22 01:36:00 -05:00
|
|
|
jobs, err := store.NewBatch(batchSize)
|
|
|
|
if err != nil {
|
2017-12-16 21:48:17 -05:00
|
|
|
logger.Error("[FeedScheduler] %v", err)
|
2017-11-22 01:36:00 -05:00
|
|
|
} else {
|
2017-12-16 21:48:17 -05:00
|
|
|
logger.Debug("[FeedScheduler] Pushing %d jobs", len(jobs))
|
2017-11-22 01:36:00 -05:00
|
|
|
workerPool.Push(jobs)
|
|
|
|
}
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
2017-11-22 01:36:00 -05:00
|
|
|
}()
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
2017-12-16 21:48:17 -05:00
|
|
|
|
2018-05-19 19:40:24 -04:00
|
|
|
// NewCleanupScheduler starts a new scheduler that clean old sessions and archive read items.
|
|
|
|
func NewCleanupScheduler(store *storage.Storage, frequency int) {
|
2017-12-16 21:48:17 -05:00
|
|
|
go func() {
|
|
|
|
c := time.Tick(time.Duration(frequency) * time.Hour)
|
2018-03-02 00:31:57 -05:00
|
|
|
for range c {
|
2017-12-16 21:48:17 -05:00
|
|
|
nbSessions := store.CleanOldSessions()
|
|
|
|
nbUserSessions := store.CleanOldUserSessions()
|
2018-05-19 19:40:24 -04:00
|
|
|
logger.Info("[CleanupScheduler] Cleaned %d sessions and %d user sessions", nbSessions, nbUserSessions)
|
|
|
|
|
|
|
|
if err := store.ArchiveEntries(); err != nil {
|
|
|
|
logger.Error("[CleanupScheduler] %v", err)
|
|
|
|
}
|
2017-12-16 21:48:17 -05:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|