@@ -306,7 +306,8 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
306
306
// so we don't need to reschedule it.
307
307
return
308
308
}
309
- var scheduleFrom time.Time
309
+
310
+ scheduleFrom := j .lastRun
310
311
if len (j .nextScheduled ) > 0 {
311
312
// always grab the last element in the slice as that is the furthest
312
313
// out in the future and the time from which we want to calculate
@@ -315,12 +316,17 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
315
316
scheduleFrom = j .nextScheduled [len (j .nextScheduled )- 1 ]
316
317
}
317
318
319
+ if scheduleFrom .IsZero () {
320
+ scheduleFrom = j .startTime
321
+ }
322
+
318
323
next := j .next (scheduleFrom )
319
324
if next .IsZero () {
320
325
// the job's next function will return zero for OneTime jobs.
321
326
// since they are one time only, they do not need rescheduling.
322
327
return
323
328
}
329
+
324
330
if next .Before (s .now ()) {
325
331
// in some cases the next run time can be in the past, for example:
326
332
// - the time on the machine was incorrect and has been synced with ntp
@@ -426,6 +432,7 @@ func (s *scheduler) selectNewJob(in newJobIn) {
426
432
}
427
433
})
428
434
}
435
+ j .startTime = next
429
436
j .nextScheduled = append (j .nextScheduled , next )
430
437
}
431
438
@@ -477,6 +484,7 @@ func (s *scheduler) selectStart() {
477
484
}
478
485
})
479
486
}
487
+ j .startTime = next
480
488
j .nextScheduled = append (j .nextScheduled , next )
481
489
s .jobs [id ] = j
482
490
}
0 commit comments