intake/cmd/monitor.go

48 lines
1.3 KiB
Go

package cmd
import (
"context"
"time"
"github.com/Jaculabilis/intake/core"
"github.com/spf13/cobra"
)
var monitorCmd = &cobra.Command{
Use: "monitor",
Short: "Run continuously and update sources according to their fetch schedule",
Long: `Run continuously and update sources.
Sources are monitored and fetched according to the schedule specified by
their INTAKE_FETCH environment variables. A schedule may be:
- "every <duration>", where <duration> is a Go duration string
- "at HH:MM[,HH:MM[...]]", where HH:MM is an hour and minute
- "on DOW[,DOW[...]] [at ...]", where DOW is an abbreviated weekday
- "on M/D[,M/D[...]] [at ...]", where M/D is a month and day
`,
Example: `
every 5m Every 5 minutes (00:00, 00:05, ...)
every 1d Once per day (at midnight)
every 7d Once per week (at midnight Sunday)
at 08:00 Once per day at 08:00
at 06:00,18:00 Twice per day at 6am and 6pm
on Tue,Thu Twice a week, on Tue and Thu
on Mon,Fri at 12:00 Twice a week, at noon on Monday and Friday
on 3/25 Once a year on March 25
on */7 Each month on the 7th
`,
Run: func(cmd *cobra.Command, args []string) {
monitor()
},
}
func init() {
rootCmd.AddCommand(monitorCmd)
}
func monitor() {
db := openAndMigrateDb()
core.BackgroundFetch(context.Background(), db, time.Minute)
}