Fix ticker not being triggered properly

This commit is contained in:
Knut Ahlers 2020-11-20 23:23:11 +01:00
parent 37dcf05b87
commit 2d4f0be64b
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

28
main.go
View file

@ -76,23 +76,29 @@ 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 <-time.NewTicker(cfg.UpdateFromAPIInterval).C:
if err := updateStats(); err != nil {
log.WithError(err).Error("Unable to update statistics from API")
}
case <-time.NewTicker(cfg.ForceSyncInterval).C:
case <-timerForceSync.C:
if err := sendAllSockets(store); err != nil {
log.WithError(err).Error("Unable to send store to all sockets")
}
case <-timerUpdateFromAPI.C:
if err := updateStats(); err != nil {
log.WithError(err).Error("Unable to update statistics from API")
}
case <-timerWebhookRegister.C:
if err := registerWebHooks(); err != nil {
log.WithError(err).Fatal("Unable to re-register webhooks")
}
}
}
}