From 7fea08c327f0ac9daa73966c9f4233f2b0102685 Mon Sep 17 00:00:00 2001 From: John Roesler Date: Mon, 18 Sep 2023 10:37:29 -0500 Subject: [PATCH] fix RemoveByID and SingletonMode (#569) --- scheduler.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scheduler.go b/scheduler.go index 09d95074..331f912f 100644 --- a/scheduler.go +++ b/scheduler.go @@ -736,12 +736,21 @@ func (s *Scheduler) removeByCondition(shouldRemove func(*Job) bool) { if !shouldRemove(job) { retainedJobs[job.id] = job } else { - job.stop() + s.stopJob(job) } } s.setJobs(retainedJobs) } +func (s *Scheduler) stopJob(job *Job) { + job.mu.Lock() + if job.runConfig.mode == singletonMode { + s.executor.singletonWgs.Delete(job.singletonWg) + } + job.mu.Unlock() + job.stop() +} + // RemoveByTag will remove jobs that match the given tag. func (s *Scheduler) RemoveByTag(tag string) error { return s.RemoveByTags(tag) @@ -784,6 +793,7 @@ func (s *Scheduler) RemoveByTagsAny(tags ...string) error { // RemoveByID removes the job from the scheduler looking up by id func (s *Scheduler) RemoveByID(job *Job) error { if _, ok := s.jobsMap()[job.id]; ok { + s.stopJob(job) delete(s.jobsMap(), job.id) return nil }