Sleep Scheduler: perform first check at startup

Instead of waiting for a minute, run the first sleep scheduler iteration
at startup.
This commit is contained in:
Sybren A. Stüvel 2022-07-18 19:30:38 +02:00
parent 83467e4c60
commit 0a5f87bc5a

@ -41,12 +41,14 @@ func (ss *SleepScheduler) Run(ctx context.Context) {
Msg("sleep scheduler starting")
defer log.Info().Msg("sleep scheduler shutting down")
waitDuration := 2 * time.Second // First check should be quickly after startup.
for {
select {
case <-ctx.Done():
return
case <-time.After(checkInterval):
case <-time.After(waitDuration):
ss.CheckSchedules(ctx)
waitDuration = checkInterval
}
}
}