how do I config task to run only once
Closed this issue · 2 comments
Hi, is it possible to run job only once in the future?
example if I want to run task for tomorrow at 10.00..
Hi! Right now it is possible but it is not pretty.
Then, since the library itself revolves around creating recurrent jobs, there is no way to declare a one-off job. It is possible to cancel the Job
after the first execution.
It will look something like:
package main
import (
"log"
"runtime"
"github.com/carlescere/scheduler"
)
var job *scheduler.Job
func main() {
job, _ = scheduler.Every().Day().At.("10:00").Run(func() {
log.Println(job)
job.Quit <- true
})
runtime.Goexit()
}
This will wait until Monday at 10:00 to log the job itself. (This particular example will panic
after the execution since quitting the job means that there won't be any goroutines running).
Personally I didn't think there would be a use-case for running one-off jobs (since the program needs to be up and running all the time for this to work), but if there is more request I will consider including it in the library.
Closing since the question has been answered.