From 5ea94731a192b8ccec5ddf0aa1cfa98c8888949d Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Mon, 5 May 2025 11:01:53 +0200 Subject: [PATCH] [-] fix `refetchTimeout` interval drift with `time.Ticker`, fixes #690 --- internal/scheduler/scheduler.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/scheduler/scheduler.go b/internal/scheduler/scheduler.go index f87dde22..56e2fcf3 100644 --- a/internal/scheduler/scheduler.go +++ b/internal/scheduler/scheduler.go @@ -122,6 +122,9 @@ func (sch *Scheduler) Run(ctx context.Context) RunStatus { sch.l.Debug("Checking for @reboot task chains...") sch.retrieveChainsAndRun(ctx, true) + // Use ticker for strict intervals + ticker := time.NewTicker(refetchTimeout * time.Second) + defer ticker.Stop() for { sch.l.Debug("Checking for task chains...") go sch.retrieveChainsAndRun(ctx, false) @@ -129,7 +132,7 @@ func (sch *Scheduler) Run(ctx context.Context) RunStatus { go sch.retrieveIntervalChainsAndRun(ctx) select { - case <-time.After(refetchTimeout * time.Second): + case <-ticker.C: // pass case <-ctx.Done(): sch.status = ContextCancelledStatus @@ -137,7 +140,6 @@ func (sch *Scheduler) Run(ctx context.Context) RunStatus { sch.status = ShutdownStatus sch.terminateChains() } - if sch.status != RunningStatus { return sch.status }