Skip to content

Commit

Permalink
remove by id should take job as id is private
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler committed Aug 20, 2023
1 parent 92efff5 commit 27c9ecb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,18 @@ func ExampleScheduler_Remove() {
// 0
}

func ExampleScheduler_RemoveByID() {
s := gocron.NewScheduler(time.UTC)

j, _ := s.Every(1).Week().Do(task)
_, _ = s.Every(1).Week().Do(task)
s.StartAsync()
s.RemoveByID(j)
fmt.Println(s.Len())
// Output:
// 1
}

func ExampleScheduler_RemoveByReference() {
s := gocron.NewScheduler(time.UTC)

Expand Down
6 changes: 3 additions & 3 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,9 @@ func (s *Scheduler) RemoveByTagsAny(tags ...string) error {
}

// RemoveByID removes the job from the scheduler looking up by id
func (s *Scheduler) RemoveByID(id uuid.UUID) error {
if _, ok := s.Jobs()[id]; ok {
delete(s.Jobs(), id)
func (s *Scheduler) RemoveByID(job *Job) error {
if _, ok := s.Jobs()[job.id]; ok {
delete(s.Jobs(), job.id)
return nil
}
return ErrJobNotFound
Expand Down

0 comments on commit 27c9ecb

Please sign in to comment.