Skip to content

Commit

Permalink
Update gocron to fix non running jobs with weeks or days units
Browse files Browse the repository at this point in the history
gocron.Every() does not run jobs with weeks or days unit
->gocron.Every(1).Monday()
->gocron.Every(1).Day
->gocron.Every(2).Days
Mainly because gocron.Every() uses a default scheduler and default scheduler sets job.shouldRun at false.
shoulRun is set to true in hte scheduleNextRun function but only for units than weeks or days, hence the fix.
  • Loading branch information
davleb authored Oct 10, 2018
1 parent c8aa208 commit b8eb1ca
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gocron.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ func (j *Job) scheduleNextRun() error {

switch j.unit {
case days:
j.shouldDo = true
j.mu.Lock()
j.nextRun = j.roundToMidnight(j.lastRun)
j.nextRun = j.nextRun.Add(j.atTime)
j.mu.Unlock()
case weeks:
j.shouldDo = true
j.mu.Lock()
j.nextRun = j.roundToMidnight(j.lastRun)
dayDiff := int(j.startDay)
Expand Down

0 comments on commit b8eb1ca

Please sign in to comment.