Skip to content

Commit

Permalink
issue-751: fix bug in selectExecJobsOutForRescheduling (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelattwood authored Jul 9, 2024
1 parent 970c539 commit 9747c90
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -426,6 +432,7 @@ func (s *scheduler) selectNewJob(in newJobIn) {
}
})
}
j.startTime = next
j.nextScheduled = append(j.nextScheduled, next)
}

Expand Down Expand Up @@ -477,6 +484,7 @@ func (s *scheduler) selectStart() {
}
})
}
j.startTime = next
j.nextScheduled = append(j.nextScheduled, next)
s.jobs[id] = j
}
Expand Down

0 comments on commit 9747c90

Please sign in to comment.