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

Can we make it execute the first time instantly after starting? #31

Open
kvzn opened this issue Dec 15, 2022 · 2 comments
Open

Can we make it execute the first time instantly after starting? #31

kvzn opened this issue Dec 15, 2022 · 2 comments

Comments

@kvzn
Copy link

kvzn commented Dec 15, 2022

When I use something like scheduler.every(1.hours()).run(move || {}), it only does the first time job after one hour after application starting, can we make it or provide an option to trigger it at once for the first round? Thank you!

@kvzn kvzn changed the title Can me make it execute the first time instantly after starting? Can we make it execute the first time instantly after starting? Dec 16, 2022
@mdsherry
Copy link
Owner

Right now with a frequency of 1/hour, it will wait until the next even hour (e.g. 1:00, 2:00, etc.) to run. The main reasoning behind this is so that you can stop and restart the program while maintaining consistent intervals between runs (unless the program was stopped when things would have run.)

Given that, would your expectation be that the task runs immediately, and then again 60 minutes later, or that it runs immediately, and the next run would be according to the hourly schedule described above?

@merc1031
Copy link

Not the original author, but I'd be interested in the ability to opt in to the latter for a particular async schedule personally.

it runs immediately, and the next run would be according to the hourly schedule described above

Essentially the way i work around it currently is on app startup i use tokio::spawn to run the action once, then put it into the AsyncScheduler in the same area of code.

The particular things i'm doing this for is
a) fetch configuration from a key value store, then setup a schedule to fetch it every so often
b) fetch expensive db data at application start, then setup a schedule to refresh it hourly.

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

3 participants