gocron
gocron copied to clipboard
[FEATURE] - OneTime jobs should have the option to be deleted on completion
Describe the bug
...
To Reproduce
func main() {
scheduler, err := gocron.NewScheduler(gocron.WithLocation(time.UTC))
if err != nil {
log.Fatal(err)
}
total := 100
var wg sync.WaitGroup
wg.Add(total)
for i := 0; i < total; i++ {
runAt := time.Now().UTC().Add(5 * time.Second)
_, err := scheduler.NewJob(
gocron.OneTimeJob(gocron.OneTimeJobStartDateTime(runAt)),
gocron.NewTask(func() {
log.Printf("running job at %s", time.Now().UTC())
wg.Done()
}),
)
if err != nil {
log.Fatal(err)
}
}
scheduler.Start()
wg.Wait()
log.Printf("total jobs: %d", len(scheduler.Jobs()))
}
Version
v2.2.9
Expected behavior
scheduler.Jobs() should return an empty slice after completing all OneTime jobs
Additional context
I don't consider this a bug. Currently, you can run a one time job, and then if you choose to, can run it manually using RunNow()
.
I think this could be changed to a feature request to optionally remove the job when done.
Currently, you can run a one time job, and then if you choose to, can run it manually using RunNow()
Why would I use RunNow()
if I can call the corresponding function directly
I don't consider this a bug.
This is a bug, OneTime jobs should be removed from the scheduler after execution (see quartz or apscheduler for example)