2023-06-25 20:23:23 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package cli // import "miniflux.app/v2/internal/cli"
|
2023-06-25 20:23:23 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/config"
|
|
|
|
"miniflux.app/v2/internal/logger"
|
|
|
|
"miniflux.app/v2/internal/storage"
|
|
|
|
"miniflux.app/v2/internal/worker"
|
2023-06-25 20:23:23 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func runScheduler(store *storage.Storage, pool *worker.Pool) {
|
|
|
|
logger.Info(`Starting background scheduler...`)
|
|
|
|
|
|
|
|
go feedScheduler(
|
|
|
|
store,
|
|
|
|
pool,
|
|
|
|
config.Opts.PollingFrequency(),
|
|
|
|
config.Opts.BatchSize(),
|
|
|
|
)
|
|
|
|
|
|
|
|
go cleanupScheduler(
|
|
|
|
store,
|
|
|
|
config.Opts.CleanupFrequencyHours(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func feedScheduler(store *storage.Storage, pool *worker.Pool, frequency, batchSize int) {
|
|
|
|
for range time.Tick(time.Duration(frequency) * time.Minute) {
|
|
|
|
jobs, err := store.NewBatch(batchSize)
|
|
|
|
logger.Info("[Scheduler:Feed] Pushing %d jobs to the queue", len(jobs))
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("[Scheduler:Feed] %v", err)
|
|
|
|
} else {
|
|
|
|
pool.Push(jobs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func cleanupScheduler(store *storage.Storage, frequency int) {
|
|
|
|
for range time.Tick(time.Duration(frequency) * time.Hour) {
|
|
|
|
runCleanupTasks(store)
|
|
|
|
}
|
|
|
|
}
|