From f870042195542ac527d9666e0aa4a8eaf88e5051 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 1 Jan 2023 15:33:51 +0100 Subject: [PATCH] [core] Fix: Remote-update cron broken as of missing field Signed-off-by: Knut Ahlers --- configRemoteUpdate.go | 11 ++++++----- main.go | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/configRemoteUpdate.go b/configRemoteUpdate.go index 714a5d8..693798b 100644 --- a/configRemoteUpdate.go +++ b/configRemoteUpdate.go @@ -9,16 +9,17 @@ import ( func updateConfigCron() string { 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() { + log.Debug("starting remote rule update") err := patchConfig( cfg.Config, "Remote Update", "twitch-bot@luzifer.io", "update rules from subscription URLs", func(cfg *configFile) error { - var hasUpdate bool + var updates int for _, r := range cfg.Rules { logger := log.WithField("rule", r.MatcherID()) @@ -30,13 +31,13 @@ func updateConfigFromRemote() { } if rhu { - hasUpdate = true + updates++ logger.Info("updated rule from remote URL") } - } - if !hasUpdate { + log.WithField("updates", updates).Debug("remote rule update finished") + if updates == 0 { return errSaveNotRequired } return nil diff --git a/main.go b/main.go index e907886..b4f615a 100644 --- a/main.go +++ b/main.go @@ -274,7 +274,9 @@ func main() { // Allow config to subscribe to external rules 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") router.Use(corsMiddleware)