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

If the system is in sleep during the time it was scheduled to run, how to trigger it once the PC comes back online? #396

Closed
shrinidhi111 opened this issue Nov 9, 2022 · 3 comments

Comments

@shrinidhi111
Copy link

Let's say I have a one-time scheduler that is created using gocron.NewScheduler().At() that is set to run at 1 PM (say)

Now suppose the computer goes to sleep at 12 PM and is back online at 2 PM.

Does the job actually execute once the system is back online? Or does it ignore it since time has passed?

If it doesn't execute, how do I ensure that it will run once the user wakes up from sleep??

@JohnRoesler
Copy link
Contributor

This isn't supported by gocron today.

I can imagine you'd need a way to write the result of each job to a persistent store, and then as part of the scheduler check for jobs in the store and make sure that they have run at the required time and if not run them immediately.

@shrinidhi111
Copy link
Author

Thanks!

If anyone else is interested, this library works with this use case (as per my testing with sleep)

https://github.com/procyon-projects/chrono

PS : Of course if you're PC is shutdown/restarted, then persistent storage will be required as @JohnRoesler suggested

@JohnRoesler
Copy link
Contributor

There is an accepted proposal golang/go#36141 for Go to add a concept of External time, which is akin to "real time" that will solve this issue in gocron. Until that point, programs will just need to be restarted in the event of a machine going to sleep.

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

2 participants