cron
cron copied to clipboard
how to execute jobs when start?
Now cron job execute when next ticker coming. For example, I set @every 5 min,but when I start my program, it must wait for 5 min to execute, I want execute when start.
There is no way to do that with the schedule. I think the best workaround is to execute your job immediately, e.g.
cron.AddJob("@every 5m", myJob)
go myJob()
Several cron implementations support @reboot
for this. "reboot" seems a little weird in the context of a go program instead of system cron, so maybe an alias like "@startup" or "@once" would be good.
The Add*
methods return an opaque ID as per the docs, it might be handy to have a companion to Remove()
that allows you to manually run a job if it's not already running. This seems like it could have a clean interaction with the scheduler, rather than needing to have a singleflight in myJob()
, though I suppose the implications for that are more broad.
just run the func once
#436