Skip to content

Commit

Permalink
fix RemoveByID and SingletonMode (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler authored Sep 18, 2023
1 parent e2a9cc0 commit 7fea08c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7fea08c

Please sign in to comment.