diff --git a/cli/cli.go b/cli/cli.go index 664fac22..6ec55035 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -11,6 +11,7 @@ import ( "miniflux.app/database" "miniflux.app/locale" "miniflux.app/logger" + feedHandler "miniflux.app/reader/handler" "miniflux.app/storage" "miniflux.app/ui/static" "miniflux.app/version" @@ -28,6 +29,7 @@ const ( flagConfigFileHelp = "Load configuration file" flagConfigDumpHelp = "Print parsed configuration values" flagHealthCheckHelp = `Perform a health check on the given endpoint (the value "auto" try to guess the health check endpoint).` + flagCronjobHelp = "Run Miniflux as a cronjob to refresh a batch of feeds and exit" ) // Parse parses command line arguments. @@ -45,6 +47,7 @@ func Parse() { flagConfigFile string flagConfigDump bool flagHealthCheck string + flagCronjob bool ) flag.BoolVar(&flagInfo, "info", false, flagInfoHelp) @@ -61,6 +64,7 @@ func Parse() { flag.StringVar(&flagConfigFile, "c", "", flagConfigFileHelp) flag.BoolVar(&flagConfigDump, "config-dump", false, flagConfigDumpHelp) flag.StringVar(&flagHealthCheck, "healthcheck", "", flagHealthCheckHelp) + flag.BoolVar(&flagCronjob, "cronjob", false, flagCronjobHelp) flag.Parse() cfg := config.NewParser() @@ -187,5 +191,21 @@ func Parse() { createAdmin(store) } + if flagCronjob { + jobs, err := store.NewBatch(config.Opts.BatchSize()) + if err != nil { + logger.Error("[Cronjob] %v", err) + } + + logger.Info("[Cronjob]] Processing %d jobs", len(jobs)) + + for _, job := range jobs { + if err := feedHandler.RefreshFeed(store, job.UserID, job.FeedID); err != nil { + logger.Error("[Cronjob] Refreshing the feed #%d returned this error: %v", job.FeedID, err) + } + } + return + } + startDaemon(store) } diff --git a/miniflux.1 b/miniflux.1 index 29f8e149..05f235b3 100644 --- a/miniflux.1 +++ b/miniflux.1 @@ -6,13 +6,19 @@ miniflux \- Minimalist and opinionated feed reader .SH SYNOPSIS \fBminiflux\fR [-vic] [-create-admin] [-debug] [-flush-sessions] [-info] [-migrate] - [-reset-feed-errors] [-reset-password] [-version] [-config-file] [-config-dump] + [-reset-feed-errors] [-reset-password] [-version] [-config-file] + [-config-dump] [-cronjob] [-healthcheck] .SH DESCRIPTION \fBminiflux\fR is a minimalist and opinionated feed reader. .SH OPTIONS .PP +.B \-cronjob +.RS 4 +Run Miniflux as a cronjob to refresh a batch of feeds and exit\&. +.RE +.PP .B \-c .RS 4 Load configuration file\&. diff --git a/service/scheduler/scheduler.go b/service/scheduler/scheduler.go index 8acc4e7f..1a2f7c98 100644 --- a/service/scheduler/scheduler.go +++ b/service/scheduler/scheduler.go @@ -38,10 +38,10 @@ func Serve(store *storage.Storage, pool *worker.Pool) { 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 { - logger.Debug("[Scheduler:Feed] Pushing %d jobs", len(jobs)) pool.Push(jobs) } }