Skip to content

Commit 9747c90

Browse files
authoredJul 9, 2024··
issue-751: fix bug in selectExecJobsOutForRescheduling (#752)
1 parent 970c539 commit 9747c90

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎scheduler.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
306306
// so we don't need to reschedule it.
307307
return
308308
}
309-
var scheduleFrom time.Time
309+
310+
scheduleFrom := j.lastRun
310311
if len(j.nextScheduled) > 0 {
311312
// always grab the last element in the slice as that is the furthest
312313
// out in the future and the time from which we want to calculate
@@ -315,12 +316,17 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
315316
scheduleFrom = j.nextScheduled[len(j.nextScheduled)-1]
316317
}
317318

319+
if scheduleFrom.IsZero() {
320+
scheduleFrom = j.startTime
321+
}
322+
318323
next := j.next(scheduleFrom)
319324
if next.IsZero() {
320325
// the job's next function will return zero for OneTime jobs.
321326
// since they are one time only, they do not need rescheduling.
322327
return
323328
}
329+
324330
if next.Before(s.now()) {
325331
// in some cases the next run time can be in the past, for example:
326332
// - the time on the machine was incorrect and has been synced with ntp
@@ -426,6 +432,7 @@ func (s *scheduler) selectNewJob(in newJobIn) {
426432
}
427433
})
428434
}
435+
j.startTime = next
429436
j.nextScheduled = append(j.nextScheduled, next)
430437
}
431438

@@ -477,6 +484,7 @@ func (s *scheduler) selectStart() {
477484
}
478485
})
479486
}
487+
j.startTime = next
480488
j.nextScheduled = append(j.nextScheduled, next)
481489
s.jobs[id] = j
482490
}

0 commit comments

Comments
 (0)
Please sign in to comment.