mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Replace daemon and scheduler package with service package
This commit is contained in:
parent
ca45765c46
commit
487852f07e
16 changed files with 287 additions and 275 deletions
46
service/scheduler/scheduler.go
Normal file
46
service/scheduler/scheduler.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
// 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.
|
||||
func Serve(cfg *config.Config, store *storage.Storage, pool *worker.Pool) {
|
||||
go feedScheduler(store, pool, cfg.PollingFrequency(), cfg.BatchSize())
|
||||
go cleanupScheduler(store, cfg.CleanupFrequency())
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cleanupScheduler(store *storage.Storage, frequency int) {
|
||||
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)
|
||||
|
||||
if err := store.ArchiveEntries(); err != nil {
|
||||
logger.Error("[Scheduler:Cleanup] %v", err)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue