Skip to content

Commit

Permalink
bugfix: check if the duration is zero before dividing in StartAt (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler committed Jun 1, 2023
1 parent 604aa9b commit 2bb9ae5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,19 @@ func (s *Scheduler) scheduleNextRun(job *Job) (bool, nextRun) {
if job.neverRan() {
// Increment startAtTime to the future
if !job.startAtTime.IsZero() && job.startAtTime.Before(now) {
duration := s.durationToNextRun(job.startAtTime, job).duration
job.setStartAtTime(job.startAtTime.Add(duration))
dur := s.durationToNextRun(job.startAtTime, job).duration
job.setStartAtTime(job.startAtTime.Add(dur))
if job.startAtTime.Before(now) {
diff := now.Sub(job.startAtTime)
duration := s.durationToNextRun(job.startAtTime, job).duration
count := diff / duration
if diff%duration != 0 {
count++
dur := s.durationToNextRun(job.startAtTime, job).duration
var count time.Duration
if dur != 0 {
count = diff / dur
if diff%dur != 0 {
count++
}
}
job.setStartAtTime(job.startAtTime.Add(duration * count))
job.setStartAtTime(job.startAtTime.Add(dur * count))
}
}
} else {
Expand Down

0 comments on commit 2bb9ae5

Please sign in to comment.