We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduler.Clear() not real remove all jobs
Steps to reproduce the behavior:
Code
package main import ( "fmt" "time" "log" "github.com/go-co-op/gocron" ) var task = func(a string) { log.Println(a) } func main() { s := gocron.NewScheduler(time.UTC) _, _ = s.Every(5).Second().Do(task,"job1") _, _ = s.Every(5).Second().Do(task,"job2") fmt.Printf("there is %d jobs.\n",len(s.Jobs())) s.StartAsync() time.Sleep(2*time.Second) s.Stop() s.Clear() fmt.Printf("After clear,there is %d jobs.\n",len(s.Jobs())) log.Println("cleared") _, _ = s.Every(1).Second().Do(task,"job3") fmt.Printf("After add new job,there is %d jobs.\n",len(s.Jobs())) s.StartAsync() time.Sleep(10*time.Second) }
Output
there is 2 jobs. 2021/03/04 23:42:05 job2 2021/03/04 23:42:05 job1 After clear,there is 0 jobs. 2021/03/04 23:42:07 cleared After add new job,there is 1 jobs. 2021/03/04 23:42:07 job3 2021/03/04 23:42:08 job3 2021/03/04 23:42:09 job3 2021/03/04 23:42:10 job1 2021/03/04 23:42:10 job2 2021/03/04 23:42:10 job3 2021/03/04 23:42:11 job3 2021/03/04 23:42:12 job3 2021/03/04 23:42:13 job3 2021/03/04 23:42:14 job3 2021/03/04 23:42:15 job3 2021/03/04 23:42:16 job3
If remove all jobs manual ,it is right.
for _, v := range s.Jobs(){ s.RemoveByReference(v) }
And suggest add StartAtTime for job
func (j *Job) StartAtTime(t time.Time) { j.Lock() defer j.Unlock() j.startAtTime = t j.startsImmediately = false }
The text was updated successfully, but these errors were encountered:
Thank you for pointing out the bug! The clear function neglects to actually stop the job's from running.
Sorry, something went wrong.
@36huo mind opening a feature request to make start at accept time.Time?
Successfully merging a pull request may close this issue.
Describe the bug
Scheduler.Clear() not real remove all jobs
To Reproduce
Steps to reproduce the behavior:
Code
Output
If remove all jobs manual ,it is right.
And suggest add StartAtTime for job
The text was updated successfully, but these errors were encountered: