Skip to content

Commit 7e1ac42

Browse files
authored
[-] fix refetchTimeout interval drift with time.Ticker, fixes #690 (#693)
1 parent b3f1eb7 commit 7e1ac42

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

internal/scheduler/scheduler.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,24 @@ func (sch *Scheduler) Run(ctx context.Context) RunStatus {
122122
sch.l.Debug("Checking for @reboot task chains...")
123123
sch.retrieveChainsAndRun(ctx, true)
124124

125+
// Use ticker for strict intervals
126+
ticker := time.NewTicker(refetchTimeout * time.Second)
127+
defer ticker.Stop()
125128
for {
126129
sch.l.Debug("Checking for task chains...")
127130
go sch.retrieveChainsAndRun(ctx, false)
128131
sch.l.Debug("Checking for interval task chains...")
129132
go sch.retrieveIntervalChainsAndRun(ctx)
130133

131134
select {
132-
case <-time.After(refetchTimeout * time.Second):
135+
case <-ticker.C:
133136
// pass
134137
case <-ctx.Done():
135138
sch.status = ContextCancelledStatus
136139
case <-sch.shutdown:
137140
sch.status = ShutdownStatus
138141
sch.terminateChains()
139142
}
140-
141143
if sch.status != RunningStatus {
142144
return sch.status
143145
}

0 commit comments

Comments
 (0)