From 47e4d5f0d14b7b8ee14bbcbeb6cf48e32fb74e18 Mon Sep 17 00:00:00 2001 From: Seunghyup Alex Oh Date: Mon, 15 Aug 2022 05:57:49 -0700 Subject: [PATCH 1/3] Protect job.RunCount() with mutex --- job.go | 2 ++ 1 file changed, 2 insertions(+) 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 } From 906e9eb75690c1d30896eb9f69a814bdb22e208f Mon Sep 17 00:00:00 2001 From: Seunghyup Alex Oh Date: Mon, 15 Aug 2022 09:44:38 -0700 Subject: [PATCH 2/3] Minor refactor usage in job.RunCount() --- scheduler.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 } From 9ac649dc525c9c2c649fabc71426c0529cf0dc6c Mon Sep 17 00:00:00 2001 From: Seunghyup Alex Oh Date: Mon, 15 Aug 2022 10:01:25 -0700 Subject: [PATCH 3/3] Lower sleeptime in TestScheduler_WaitForSchedules --- scheduler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()