added schedule delay in conf, cronjobs are scheduled with this delay in between
This commit is contained in:
parent
cb70a14209
commit
af165c345a
2 changed files with 17 additions and 2 deletions
|
@ -44,3 +44,5 @@ browserless:
|
||||||
url: http://your.browserless:1234
|
url: http://your.browserless:1234
|
||||||
gin:
|
gin:
|
||||||
debug: false
|
debug: false
|
||||||
|
schedule:
|
||||||
|
delay: "5s"
|
15
main.go
15
main.go
|
@ -172,6 +172,17 @@ func (web *Web) initCronJobs() {
|
||||||
web.db.Model(&Filter{}).Find(&cronFilters, "type = 'cron' AND var2 = 'yes'")
|
web.db.Model(&Filter{}).Find(&cronFilters, "type = 'cron' AND var2 = 'yes'")
|
||||||
web.cronWatch = make(map[uint]cron.EntryID, len(cronFilters))
|
web.cronWatch = make(map[uint]cron.EntryID, len(cronFilters))
|
||||||
web.cron = cron.New()
|
web.cron = cron.New()
|
||||||
|
web.cron.Start()
|
||||||
|
|
||||||
|
// add some delay to cron jobs, so watches with the same schedule don't
|
||||||
|
// 'burst' at the same time after restarting GoWatch
|
||||||
|
cronDelayStr := viper.GetString("schedule.delay")
|
||||||
|
cronDelay, delayErr := time.ParseDuration(cronDelayStr)
|
||||||
|
if delayErr == nil {
|
||||||
|
log.Println("Delaying job startup by:", cronDelay.String())
|
||||||
|
} else {
|
||||||
|
web.startupWarning("Could not parse schedule.delay: ", cronDelayStr)
|
||||||
|
}
|
||||||
for i := range cronFilters {
|
for i := range cronFilters {
|
||||||
cronFilter := &cronFilters[i]
|
cronFilter := &cronFilters[i]
|
||||||
entryID, err := web.cron.AddFunc(cronFilter.Var1, func() { triggerSchedule(cronFilter.WatchID, web, &cronFilter.ID) })
|
entryID, err := web.cron.AddFunc(cronFilter.Var1, func() { triggerSchedule(cronFilter.WatchID, web, &cronFilter.ID) })
|
||||||
|
@ -181,6 +192,9 @@ func (web *Web) initCronJobs() {
|
||||||
}
|
}
|
||||||
log.Println("Started CronJob for WatchID", cronFilter.WatchID, "with schedule:", cronFilter.Var1)
|
log.Println("Started CronJob for WatchID", cronFilter.WatchID, "with schedule:", cronFilter.Var1)
|
||||||
web.cronWatch[cronFilter.ID] = entryID
|
web.cronWatch[cronFilter.ID] = entryID
|
||||||
|
|
||||||
|
if delayErr == nil {
|
||||||
|
time.Sleep(cronDelay)
|
||||||
}
|
}
|
||||||
if viper.IsSet("database.prune") {
|
if viper.IsSet("database.prune") {
|
||||||
pruneSchedule := viper.GetString("database.prune")
|
pruneSchedule := viper.GetString("database.prune")
|
||||||
|
@ -190,7 +204,6 @@ func (web *Web) initCronJobs() {
|
||||||
}
|
}
|
||||||
log.Println("Started DB prune cronjob:", pruneSchedule)
|
log.Println("Started DB prune cronjob:", pruneSchedule)
|
||||||
}
|
}
|
||||||
web.cron.Start()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (web *Web) initNotifiers() {
|
func (web *Web) initNotifiers() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue