2017-11-20 06:10:04 +01: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.
|
|
|
|
|
|
|
|
package scheduler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2017-11-22 07:36:00 +01:00
|
|
|
|
2017-12-16 03:55:57 +01:00
|
|
|
"github.com/miniflux/miniflux/logger"
|
2017-12-13 06:48:13 +01:00
|
|
|
"github.com/miniflux/miniflux/storage"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
2017-12-17 03:48:17 +01: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 07:36:00 +01:00
|
|
|
go func() {
|
|
|
|
c := time.Tick(time.Duration(frequency) * time.Minute)
|
2018-03-02 06:31:57 +01:00
|
|
|
for range c {
|
2017-11-22 07:36:00 +01:00
|
|
|
jobs, err := store.NewBatch(batchSize)
|
|
|
|
if err != nil {
|
2017-12-17 03:48:17 +01:00
|
|
|
logger.Error("[FeedScheduler] %v", err)
|
2017-11-22 07:36:00 +01:00
|
|
|
} else {
|
2017-12-17 03:48:17 +01:00
|
|
|
logger.Debug("[FeedScheduler] Pushing %d jobs", len(jobs))
|
2017-11-22 07:36:00 +01:00
|
|
|
workerPool.Push(jobs)
|
|
|
|
}
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
2017-11-22 07:36:00 +01:00
|
|
|
}()
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
2017-12-17 03:48:17 +01:00
|
|
|
|
|
|
|
// NewSessionScheduler starts a new scheduler that clean old sessions.
|
|
|
|
func NewSessionScheduler(store *storage.Storage, frequency int) {
|
|
|
|
go func() {
|
|
|
|
c := time.Tick(time.Duration(frequency) * time.Hour)
|
2018-03-02 06:31:57 +01:00
|
|
|
for range c {
|
2017-12-17 03:48:17 +01:00
|
|
|
nbSessions := store.CleanOldSessions()
|
|
|
|
nbUserSessions := store.CleanOldUserSessions()
|
2017-12-19 05:52:46 +01:00
|
|
|
logger.Info("[SessionScheduler] cleaned %d sessions and %d user sessions", nbSessions, nbUserSessions)
|
2017-12-17 03:48:17 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|