From f4b28cdbe2db50e9c339f1f09d4fe88b502466ea Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Thu, 3 Nov 2022 04:23:06 +0900 Subject: [PATCH] Remove the code that double check last run time and current time --- scheduler.go | 6 ------ scheduler_test.go | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/scheduler.go b/scheduler.go index 69f03103..508f4323 100644 --- a/scheduler.go +++ b/scheduler.go @@ -356,12 +356,6 @@ func (s *Scheduler) calculateDays(job *Job, lastRun time.Time) nextRun { if job.getInterval() == 1 { lastRunDayPlusJobAtTime := s.roundToMidnight(lastRun).Add(job.getAtTime(lastRun)) - // handle occasional occurrence of job running to quickly / too early such that last run was within a second of now - lastRunUnix, nowUnix := job.LastRun().Unix(), s.now().Unix() - if lastRunUnix == nowUnix || lastRunUnix == nowUnix-1 || lastRunUnix == nowUnix+1 { - lastRun = lastRunDayPlusJobAtTime - } - if shouldRunToday(lastRun, lastRunDayPlusJobAtTime) { return nextRun{duration: until(lastRun, lastRunDayPlusJobAtTime), dateTime: lastRunDayPlusJobAtTime} } diff --git a/scheduler_test.go b/scheduler_test.go index c8eb89d1..f4f3e89e 100644 --- a/scheduler_test.go +++ b/scheduler_test.go @@ -967,7 +967,7 @@ func TestScheduler_CalculateNextRun(t *testing.T) { {name: "daily job just ran at 5:30AM and should be scheduled for today at 8:30AM", job: &Job{mu: &jobMutex{}, interval: 1, unit: days, atTimes: []time.Duration{8*time.Hour + 30*time.Minute}, lastRun: januaryFirst2020At(5, 30, 0)}, wantTimeUntilNextRun: 3 * time.Hour}, {name: "job runs every 2 days, just ran at 5:30AM and should be scheduled for 2 days at 8:30AM", job: &Job{mu: &jobMutex{}, interval: 2, unit: days, atTimes: []time.Duration{8*time.Hour + 30*time.Minute}, lastRun: januaryFirst2020At(5, 30, 0)}, wantTimeUntilNextRun: (2 * day) + 3*time.Hour}, {name: "job runs every 2 days, just ran at 8:30AM and should be scheduled for 2 days at 8:30AM", job: &Job{mu: &jobMutex{}, interval: 2, unit: days, atTimes: []time.Duration{8*time.Hour + 30*time.Minute}, lastRun: januaryFirst2020At(8, 30, 0)}, wantTimeUntilNextRun: 2 * day}, - {name: "daily, last run was 1 second ago", job: &Job{mu: &jobMutex{}, interval: 1, unit: days, atTimes: []time.Duration{12 * time.Hour}, lastRun: ft.Now(time.UTC).Add(-time.Second)}, wantTimeUntilNextRun: 1 * day}, + {name: "daily, last run was 1 second ago", job: &Job{mu: &jobMutex{}, interval: 1, unit: days, atTimes: []time.Duration{12 * time.Hour}, lastRun: ft.Now(time.UTC).Add(-time.Second)}, wantTimeUntilNextRun: 1 * time.Second}, //// WEEKS {name: "every week should run in 7 days", job: &Job{mu: &jobMutex{}, interval: 1, unit: weeks, lastRun: januaryFirst2020At(0, 0, 0)}, wantTimeUntilNextRun: 7 * day}, {name: "every week with .At time rule should run respect .At time rule", job: &Job{mu: &jobMutex{}, interval: 1, atTimes: []time.Duration{_getHours(9) + _getMinutes(30)}, unit: weeks, lastRun: januaryFirst2020At(9, 30, 0)}, wantTimeUntilNextRun: 7 * day},