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

What happens when a job is "missed" at the scheduled time? #554

Closed
Noam5 opened this issue Nov 22, 2022 · 1 comment
Closed

What happens when a job is "missed" at the scheduled time? #554

Noam5 opened this issue Nov 22, 2022 · 1 comment

Comments

@Noam5
Copy link

Noam5 commented Nov 22, 2022

For example the code:

import schedule
import time

def job(t):
    print "I'm working...", t
    return

schedule.every().day.at("10:00").do(job,'It is 01:00')

while True:
    schedule.run_pending()
    time.sleep(60) # wait one minute

But the computer was hibernating until 11:00? will the task still be scheduled? what about 23 hours later?

@SijmenHuizenga
Copy link
Collaborator

In the example you provided, the job is scheduled to run every day at 10:00. If the computer is hibernating until 11:00, the scheduled task will be run whenever the computer wakes up and the run_pending() function is called.

Every job has an next_run variable with a datetime that indicates when the next job should run. This can be seen when you print the job:

print(repr(schedule.every().day.at("10:00").do(job,'It is 01:00')))
# Every 1 day at 10:00:00 do job('It is 01:00') (last run: [never], next run: 2023-04-11 10:00:00)

The run_pending simply looks at all the jobs' next_run, and whenever the current time is equal or after the next_run, it will run the job and calculate the new next_run. So when the program execution was paused (run_pending was not called for a long time), then whenever the next time run_pending runs, all missed jobs are ran.

Happy scheduling!

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