cron icon indicating copy to clipboard operation
cron copied to clipboard

how to execute jobs when start?

Open iziyang opened this issue 4 years ago • 5 comments

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.

iziyang avatar Mar 29 '20 02:03 iziyang

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()

robfig avatar Mar 29 '20 16:03 robfig

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.

tsarna avatar Jul 30 '20 22:07 tsarna

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.

flowchartsman avatar Sep 03 '20 14:09 flowchartsman

just run the func once

freecells avatar Dec 23 '20 06:12 freecells

#436

zeewell avatar Apr 22 '22 03:04 zeewell