fix: anchor floor on re-enable; breaker on scheduled panic; propagate next-run err; reject negative interval; close phantom runs on startup
This commit is contained in:
@@ -19,7 +19,7 @@ const pollInterval = 30 * time.Second
|
||||
// run, or one interval after the schedule anchor if it has never completed one.
|
||||
func NextRun(interval time.Duration, anchor time.Time, lastFinished *time.Time) time.Time {
|
||||
base := anchor
|
||||
if lastFinished != nil {
|
||||
if lastFinished != nil && lastFinished.After(anchor) {
|
||||
base = *lastFinished
|
||||
}
|
||||
return base.Add(interval)
|
||||
|
||||
@@ -19,6 +19,12 @@ func TestNextRun(t *testing.T) {
|
||||
if got := NextRun(time.Hour, anchor, &fin); !got.Equal(fin.Add(time.Hour)) {
|
||||
t.Fatalf("recurring: got %v", got)
|
||||
}
|
||||
// Re-enable: anchor is newer than a stale lastFinished from before re-enable →
|
||||
// use anchor, not the stale lastFinished (which would fire immediately/in the past).
|
||||
staleFin := anchor.Add(-2 * time.Hour)
|
||||
if got := NextRun(time.Hour, anchor, &staleFin); !got.Equal(anchor.Add(time.Hour)) {
|
||||
t.Fatalf("re-enable: got %v, want %v", got, anchor.Add(time.Hour))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDueTaskIDs(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user