Add the possibility to run Miniflux as a cronjob
This commit is contained in:
parent
c3250257b1
commit
c85b19098d
3 changed files with 28 additions and 2 deletions
20
cli/cli.go
20
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)
|
||||
}
|
||||
|
|
|
@ -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\&.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue