templating: Rework timers

This commit is contained in:
Tom Wiesing 2023-01-31 12:51:54 +01:00
parent 66eb13df30
commit 2d163a4dad
No known key found for this signature in database
9 changed files with 232 additions and 46 deletions

View file

@ -119,18 +119,18 @@ func (control *Cron) Start(ctx context.Context, signal <-chan struct{}) <-chan s
run()
zerolog.Ctx(ctx).Debug().Msg("Cron() beginnning scheduling")
timer := timex.NewTimer()
t := timex.NewTimer()
defer timex.ReleaseTimer(t)
for {
timex.StopTimer(timer)
timer.Reset(control.Config.CronInterval)
timex.StopTimer(t)
t.Reset(control.Config.CronInterval)
select {
case <-timer.C:
case <-t.C:
zerolog.Ctx(ctx).Debug().Msg("Cron() timer fired")
case <-signal:
zerolog.Ctx(ctx).Debug().Msg("Cron() received signal")
case <-ctx.Done():
timex.StopTimer(timer)
return
}