mirror of
https://github.com/Luzifer/twitch-manager.git
synced 2024-12-30 08:31:18 +00:00
Fix ticker not being triggered properly
This commit is contained in:
parent
37dcf05b87
commit
2d4f0be64b
1 changed files with 13 additions and 7 deletions
20
main.go
20
main.go
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue