Skip to content
New issue

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

how to execute jobs when start? #297

Open
iziyang opened this issue Mar 29, 2020 · 5 comments
Open

how to execute jobs when start? #297

iziyang opened this issue Mar 29, 2020 · 5 comments

Comments

@iziyang
Copy link

iziyang commented Mar 29, 2020

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.

@robfig
Copy link
Owner

robfig commented Mar 29, 2020

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

@tsarna
Copy link

tsarna commented Jul 30, 2020

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.

@flowchartsman
Copy link

flowchartsman commented Sep 3, 2020

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.

@freecells
Copy link

just run the func once

@zeewell
Copy link

zeewell commented Apr 22, 2022

#436

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants