From 7168288266bfa16e91b5a8d9a4fe73f85ad0ecd7 Mon Sep 17 00:00:00 2001 From: Alexander Trost Date: Mon, 28 Oct 2024 21:42:17 +0100 Subject: [PATCH] fix: cron scheduler duplicating logic Signed-off-by: Alexander Trost --- pkg/croner/scheduler.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/croner/scheduler.go b/pkg/croner/scheduler.go index 01eb266d1..84391f5e6 100644 --- a/pkg/croner/scheduler.go +++ b/pkg/croner/scheduler.go @@ -74,13 +74,20 @@ func NewScheduler(p SchedulerParams) (*Scheduler, error) { return cj, nil } - ctx, cancel := context.WithCancel(ctxCancel) - s.jobs.Store(cj.Name, &jobWrapper{ - ctx: ctx, - cancel: cancel, - - schedule: cj.Schedule, - }) + jw, ok := s.jobs.Load(cj.Name) + if !ok { + ctx, cancel := context.WithCancel(ctxCancel) + s.jobs.Store(cj.Name, &jobWrapper{ + ctx: ctx, + cancel: cancel, + + schedule: cj.Schedule, + }) + } else { + if cj.Schedule != jw.schedule { + jw.schedule = cj.Schedule + } + } return cj, nil }),