From 116a625e6eb05b305b3ebf8cce26b2211325f282 Mon Sep 17 00:00:00 2001 From: bbaa Date: Thu, 21 Sep 2023 17:31:33 +0800 Subject: [PATCH 1/2] fix Scheduler.NextRun() not returning the correct value --- scheduler.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scheduler.go b/scheduler.go index 926730b8..119f4bdd 100644 --- a/scheduler.go +++ b/scheduler.go @@ -520,8 +520,15 @@ func (s *Scheduler) NextRun() (*Job, time.Time) { var jobID uuid.UUID var nearestRun time.Time + flag := false for _, job := range s.jobsMap() { nr := job.NextRun() + if !flag && s.now().Before(nr) { + nearestRun = nr + jobID = job.id + flag = true + continue + } if nr.Before(nearestRun) && s.now().Before(nr) { nearestRun = nr jobID = job.id From 30f015cb7bf58b3d7743795b80d596e2aa5e72fe Mon Sep 17 00:00:00 2001 From: John Roesler Date: Thu, 21 Sep 2023 11:16:33 -0500 Subject: [PATCH 2/2] if the nearest run is zero we'll never be before it --- scheduler.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/scheduler.go b/scheduler.go index 119f4bdd..0f3657aa 100644 --- a/scheduler.go +++ b/scheduler.go @@ -520,16 +520,9 @@ func (s *Scheduler) NextRun() (*Job, time.Time) { var jobID uuid.UUID var nearestRun time.Time - flag := false for _, job := range s.jobsMap() { nr := job.NextRun() - if !flag && s.now().Before(nr) { - nearestRun = nr - jobID = job.id - flag = true - continue - } - if nr.Before(nearestRun) && s.now().Before(nr) { + if (nr.Before(nearestRun) || nearestRun.IsZero()) && s.now().Before(nr) { nearestRun = nr jobID = job.id }