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

20
main.go
View file

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