[core] Fix: Remote-update cron broken as of missing field

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-01-01 15:33:51 +01:00
parent 9ec1117490
commit f870042195
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 9 additions and 6 deletions

View file

@ -9,16 +9,17 @@ import (
func updateConfigCron() string { func updateConfigCron() string {
minute := rand.Intn(60) //nolint:gomnd,gosec // Only used to distribute load minute := rand.Intn(60) //nolint:gomnd,gosec // Only used to distribute load
return fmt.Sprintf("%d * * * *", minute) return fmt.Sprintf("0 %d * * * *", minute)
} }
func updateConfigFromRemote() { func updateConfigFromRemote() {
log.Debug("starting remote rule update")
err := patchConfig( err := patchConfig(
cfg.Config, cfg.Config,
"Remote Update", "twitch-bot@luzifer.io", "Remote Update", "twitch-bot@luzifer.io",
"update rules from subscription URLs", "update rules from subscription URLs",
func(cfg *configFile) error { func(cfg *configFile) error {
var hasUpdate bool var updates int
for _, r := range cfg.Rules { for _, r := range cfg.Rules {
logger := log.WithField("rule", r.MatcherID()) logger := log.WithField("rule", r.MatcherID())
@ -30,13 +31,13 @@ func updateConfigFromRemote() {
} }
if rhu { if rhu {
hasUpdate = true updates++
logger.Info("updated rule from remote URL") logger.Info("updated rule from remote URL")
} }
} }
if !hasUpdate { log.WithField("updates", updates).Debug("remote rule update finished")
if updates == 0 {
return errSaveNotRequired return errSaveNotRequired
} }
return nil return nil

View file

@ -274,7 +274,9 @@ func main() {
// Allow config to subscribe to external rules // Allow config to subscribe to external rules
updCron := updateConfigCron() updCron := updateConfigCron()
cronService.AddFunc(updCron, updateConfigFromRemote) if _, err = cronService.AddFunc(updCron, updateConfigFromRemote); err != nil {
log.WithError(err).Error("adding remote-update cron")
}
log.WithField("cron", updCron).Debug("Initialized remote update cron") log.WithField("cron", updCron).Debug("Initialized remote update cron")
router.Use(corsMiddleware) router.Use(corsMiddleware)