From cf2f500908e586766d190974350f62d77995dd77 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:23:16 -0600 Subject: [PATCH 1/2] Bump golangci/golangci-lint-action from 6.1.1 to 6.2.0 (#817) Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6.1.1 to 6.2.0. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](https://github.com/golangci/golangci-lint-action/compare/v6.1.1...v6.2.0) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: John Roesler --- .github/workflows/go_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go_test.yml b/.github/workflows/go_test.yml index 7bd9bd2..b2e8f20 100644 --- a/.github/workflows/go_test.yml +++ b/.github/workflows/go_test.yml @@ -25,7 +25,7 @@ with: go-version: ${{ matrix.go-version }} - name: golangci-lint - uses: golangci/golangci-lint-action@v6.1.1 + uses: golangci/golangci-lint-action@v6.2.0 with: version: v1.59.1 - name: test From 5b49603168223f6842ccc8b327722645633a8b6f Mon Sep 17 00:00:00 2001 From: John Roesler Date: Tue, 28 Jan 2025 21:22:56 -0600 Subject: [PATCH 2/2] working to handle edge cases where a job can be run twice, unexpectedly (#810) --- job.go | 8 ++++---- scheduler.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/job.go b/job.go index 8bc8d44..65fe73b 100644 --- a/job.go +++ b/job.go @@ -864,7 +864,7 @@ func (d dailyJob) next(lastRun time.Time) time.Time { } firstPass = false - startNextDay := time.Date(lastRun.Year(), lastRun.Month(), lastRun.Day()+int(d.interval), 0, 0, 0, lastRun.Nanosecond(), lastRun.Location()) + startNextDay := time.Date(lastRun.Year(), lastRun.Month(), lastRun.Day()+int(d.interval), 0, 0, 0, 0, lastRun.Location()) return d.nextDay(startNextDay, firstPass) } @@ -872,7 +872,7 @@ func (d dailyJob) nextDay(lastRun time.Time, firstPass bool) time.Time { for _, at := range d.atTimes { // sub the at time hour/min/sec onto the lastScheduledRun's values // to use in checks to see if we've got our next run time - atDate := time.Date(lastRun.Year(), lastRun.Month(), lastRun.Day(), at.Hour(), at.Minute(), at.Second(), lastRun.Nanosecond(), lastRun.Location()) + atDate := time.Date(lastRun.Year(), lastRun.Month(), lastRun.Day(), at.Hour(), at.Minute(), at.Second(), 0, lastRun.Location()) if firstPass && atDate.After(lastRun) { // checking to see if it is after i.e. greater than, @@ -918,7 +918,7 @@ func (w weeklyJob) nextWeekDayAtTime(lastRun time.Time, firstPass bool) time.Tim for _, at := range w.atTimes { // sub the at time hour/min/sec onto the lastScheduledRun's values // to use in checks to see if we've got our next run time - atDate := time.Date(lastRun.Year(), lastRun.Month(), lastRun.Day()+int(weekDayDiff), at.Hour(), at.Minute(), at.Second(), lastRun.Nanosecond(), lastRun.Location()) + atDate := time.Date(lastRun.Year(), lastRun.Month(), lastRun.Day()+int(weekDayDiff), at.Hour(), at.Minute(), at.Second(), 0, lastRun.Location()) if firstPass && atDate.After(lastRun) { // checking to see if it is after i.e. greater than, @@ -986,7 +986,7 @@ func (m monthlyJob) nextMonthDayAtTime(lastRun time.Time, days []int, firstPass for _, at := range m.atTimes { // sub the day, and the at time hour/min/sec onto the lastScheduledRun's values // to use in checks to see if we've got our next run time - atDate := time.Date(lastRun.Year(), lastRun.Month(), day, at.Hour(), at.Minute(), at.Second(), lastRun.Nanosecond(), lastRun.Location()) + atDate := time.Date(lastRun.Year(), lastRun.Month(), day, at.Hour(), at.Minute(), at.Second(), 0, lastRun.Location()) if atDate.Month() != lastRun.Month() { // this check handles if we're setting a day not in the current month diff --git a/scheduler.go b/scheduler.go index 63f353c..a981fdc 100644 --- a/scheduler.go +++ b/scheduler.go @@ -335,7 +335,7 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) { return } - scheduleFrom := j.lastRun + var scheduleFrom time.Time if len(j.nextScheduled) > 0 { // always grab the last element in the slice as that is the furthest // out in the future and the time from which we want to calculate @@ -366,6 +366,15 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) { } } + if slices.Contains(j.nextScheduled, next) { + // if the next value is a duplicate of what's already in the nextScheduled slice, for example: + // - the job is being rescheduled off the same next run value as before + // increment to the next, next value + for slices.Contains(j.nextScheduled, next) { + next = j.next(next) + } + } + // Clean up any existing timer to prevent leaks if j.timer != nil { j.timer.Stop()