diff --git a/job.go b/job.go index 8d79e846..136be1e6 100644 --- a/job.go +++ b/job.go @@ -434,6 +434,8 @@ func (j *Job) setNextRun(t time.Time) { // RunCount returns the number of time the job ran so far func (j *Job) RunCount() int { + j.mu.Lock() + defer j.mu.Unlock() return j.runCount } diff --git a/scheduler.go b/scheduler.go index 1fa8407c..75fddf9b 100644 --- a/scheduler.go +++ b/scheduler.go @@ -323,14 +323,14 @@ func (s *Scheduler) calculateWeeks(job *Job, lastRun time.Time) nextRun { } func (s *Scheduler) calculateTotalDaysDifference(lastRun time.Time, daysToWeekday int, job *Job) int { - if job.getInterval() > 1 && job.RunCount() < len(job.Weekdays()) { // just count weeks after the first jobs were done - return daysToWeekday - } - if job.getInterval() > 1 && job.RunCount() >= len(job.Weekdays()) { + if job.getInterval() > 1 { + // just count weeks after the first jobs were done + if job.RunCount() < len(job.Weekdays()) { + return daysToWeekday + } if daysToWeekday > 0 { return int(job.getInterval())*7 - (allWeekDays - daysToWeekday) } - return int(job.getInterval()) * 7 } diff --git a/scheduler_test.go b/scheduler_test.go index 833ae0bd..c8eb89d1 100644 --- a/scheduler_test.go +++ b/scheduler_test.go @@ -1841,7 +1841,7 @@ func TestScheduler_WaitForSchedules(t *testing.T) { require.NoError(t, err) s.StartAsync() - time.Sleep(1100 * time.Millisecond) + time.Sleep(1050 * time.Millisecond) s.Stop() counterMutex.RLock()