Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-751: Address Bug in Rescheduling #752

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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