issue-751: fix bug in selectExecJobsOutForRescheduling (#752)

This commit is contained in:
Samuel Attwood 2024-07-09 10:39:51 -04:00 committed by GitHub
parent 970c5399bc
commit 9747c90947
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 1 deletions

View File

@ -306,7 +306,8 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
// so we don't need to reschedule it.
return
}
var scheduleFrom time.Time
scheduleFrom := j.lastRun
if len(j.nextScheduled) > 0 {
// always grab the last element in the slice as that is the furthest
// out in the future and the time from which we want to calculate
@ -315,12 +316,17 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
scheduleFrom = j.nextScheduled[len(j.nextScheduled)-1]
}
if scheduleFrom.IsZero() {
scheduleFrom = j.startTime
}
next := j.next(scheduleFrom)
if next.IsZero() {
// the job's next function will return zero for OneTime jobs.
// since they are one time only, they do not need rescheduling.
return
}
if next.Before(s.now()) {
// in some cases the next run time can be in the past, for example:
// - the time on the machine was incorrect and has been synced with ntp
@ -426,6 +432,7 @@ func (s *scheduler) selectNewJob(in newJobIn) {
}
})
}
j.startTime = next
j.nextScheduled = append(j.nextScheduled, next)
}
@ -477,6 +484,7 @@ func (s *scheduler) selectStart() {
}
})
}
j.startTime = next
j.nextScheduled = append(j.nextScheduled, next)
s.jobs[id] = j
}