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 (
|
2023-09-25 01:32:09 +02:00
|
|
|
"log/slog"
|
2023-06-25 20:23:23 +02:00
|
|
|
"time"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/config"
|
|
|
|
"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) {
|
2023-09-25 01:32:09 +02:00
|
|
|
slog.Debug(`Starting background scheduler...`)
|
2023-06-25 20:23:23 +02:00
|
|
|
|
|
|
|
go feedScheduler(
|
|
|
|
store,
|
|
|
|
pool,
|
|
|
|
config.Opts.PollingFrequency(),
|
|
|
|
config.Opts.BatchSize(),
|
2023-10-21 00:12:02 +02:00
|
|
|
config.Opts.PollingParsingErrorLimit(),
|
2023-06-25 20:23:23 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
go cleanupScheduler(
|
|
|
|
store,
|
|
|
|
config.Opts.CleanupFrequencyHours(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-10-21 00:12:02 +02:00
|
|
|
func feedScheduler(store *storage.Storage, pool *worker.Pool, frequency, batchSize, errorLimit int) {
|
2023-06-25 20:23:23 +02:00
|
|
|
for range time.Tick(time.Duration(frequency) * time.Minute) {
|
2023-10-21 00:12:02 +02:00
|
|
|
// Generate a batch of feeds for any user that has feeds to refresh.
|
|
|
|
batchBuilder := store.NewBatchBuilder()
|
|
|
|
batchBuilder.WithBatchSize(batchSize)
|
|
|
|
batchBuilder.WithErrorLimit(errorLimit)
|
|
|
|
batchBuilder.WithoutDisabledFeeds()
|
|
|
|
batchBuilder.WithNextCheckExpired()
|
|
|
|
|
|
|
|
if jobs, err := batchBuilder.FetchJobs(); err != nil {
|
2023-09-25 01:32:09 +02:00
|
|
|
slog.Error("Unable to fetch jobs from database", slog.Any("error", err))
|
2023-11-30 06:48:14 +01:00
|
|
|
} else if len(jobs) > 0 {
|
2023-09-25 01:32:09 +02:00
|
|
|
slog.Info("Created a batch of feeds",
|
|
|
|
slog.Int("nb_jobs", len(jobs)),
|
|
|
|
)
|
2023-06-25 20:23:23 +02:00
|
|
|
pool.Push(jobs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func cleanupScheduler(store *storage.Storage, frequency int) {
|
|
|
|
for range time.Tick(time.Duration(frequency) * time.Hour) {
|
|
|
|
runCleanupTasks(store)
|
|
|
|
}
|
|
|
|
}
|