I am using python schedule module to schedule a bunch (40+) of daily recurring jobs on an heroku (Hobby Tier) instance. I run a script as a entry point (called on every reboot of the machine):
if __name__ == "__main__":
schedule.every().day.at(session_time).do(_run_leetcode_session, bot, chat_id, team_name=team_name)
Out of the ~40 jobs I schedule, looks like some of them are not run. To. verify I run the following debug script:
for job in schedule.jobs:
logging.info(job)
And I get the following log
2020-03-05 23:06:31,606 - root - INFO - Every 1 day at 12:00:00 do _run_leetcode_session(<telegram.bot.Bot object at 0x7f9576039b50>, '-375976592', team_name='🎊Leetcode Team 100') (last run: 2020-03-05 12:00:01, next run: 2020-03-06 12:00:00)
2020-03-05 23:06:31,606 - root - INFO - Every 1 day at 15:30:00 do _run_leetcode_session(<telegram.bot.Bot object at 0x7f9576039b50>, '-281586101', team_name='🧶Leetcode Practice 201') (last run: [never], next run: 2020-03-05 15:30:00)
The first line is fine, but the log exhibits a non-expected behaviour in the second line:
at 2020-03-05 23:06:31
I am being told that (last run: [never], next run: 2020-03-05 15:30:00)
, in fact the job wasn't executed on 2020-03-05 15:30:00
and now the next run date is in the past. How to interpret this?
Is this a bug in the library? Is there a problem in the machine? Is there some problem with the threading set up?
This happens because python schedule
module does not handle errors automatically, so if one job breaks the scheduler breaks and all the following jobs will be not executed.
A workaround is using an implementation that catches exceptions like this SafeScheduler