From 2d4f0be64bc2160efd16f6d49f0469baf6eb86ff Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 20 Nov 2020 23:23:11 +0100 Subject: [PATCH] Fix ticker not being triggered properly --- main.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 6110dbb..9812f6b 100644 --- a/main.go +++ b/main.go @@ -76,21 +76,27 @@ func main() { log.WithError(err).Fatal("Unable to register webhooks") } + var ( + timerForceSync = time.NewTicker(cfg.ForceSyncInterval) + timerUpdateFromAPI = time.NewTicker(cfg.UpdateFromAPIInterval) + timerWebhookRegister = time.NewTicker(cfg.WebHookTimeout) + ) + for { select { - case <-time.NewTicker(cfg.WebHookTimeout).C: - if err := registerWebHooks(); err != nil { - log.WithError(err).Fatal("Unable to re-register webhooks") + case <-timerForceSync.C: + if err := sendAllSockets(store); err != nil { + log.WithError(err).Error("Unable to send store to all sockets") } - case <-time.NewTicker(cfg.UpdateFromAPIInterval).C: + case <-timerUpdateFromAPI.C: if err := updateStats(); err != nil { log.WithError(err).Error("Unable to update statistics from API") } - case <-time.NewTicker(cfg.ForceSyncInterval).C: - if err := sendAllSockets(store); err != nil { - log.WithError(err).Error("Unable to send store to all sockets") + case <-timerWebhookRegister.C: + if err := registerWebHooks(); err != nil { + log.WithError(err).Fatal("Unable to re-register webhooks") } }