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

APScheduler With CronTrigger Skipped A Day Due To Daylight Savings #606

Open
slipknotstrat opened this issue Mar 14, 2022 · 4 comments
Open
Labels

Comments

@slipknotstrat
Copy link

I have a job scheduled to take place at midnight every day, I use the background scheduler and crontrigger with hour and minute set to zero, timezone set to 'US/Pacific', jitter set to 10.
Its worked flawlessly until yesterday. Changes due to daylight savings take place between 2AM and 3AM, so scheduling at midnight shouldnt create any issues according to the docs.

Heres the generating code:

sched = BackgroundScheduler()
sched.add_job(NewDay, CronTrigger(hour=0, minute=0, timezone='US/Pacific', jitter=10))
sched.start()

Heres the apscheduler log:

2022-03-13 00:00:07,641 - 2152 - INFO - Running job "NewDay (trigger: cron[hour='0', minute='0'], next run at: 2022-03-15 00:00:06 PDT)" (scheduled at 2022-03-13 00:00:07.580111-08:00)
2022-03-13 00:00:07,641 - 2152 - INFO - Syncing To Excel DB On Sun Mar 13 00:00:07 2022
2022-03-13 00:00:07,908 - 2152 - INFO - Job "NewDay (trigger: cron[hour='0', minute='0'], next run at: 2022-03-15 00:00:06 PDT)" executed successfully

As you can see, 'next run' is scheduled to run at midnight two days after the last job has run, it skips March 14 entirely.

This is being run on a Windows 10 system in southern California.

Please advise how to remedy - thank you.

(Please be mindful that while I am an older engineer, I am a novice python programmer. If I have missed something glaringly obvious, or posted this to the wrong place, my apologies in advance.)

@agronholm
Copy link
Owner

I've reproduced the problem with this script:

from datetime import datetime

from apscheduler.triggers.cron import CronTrigger

t = CronTrigger(hour=0, timezone='US/Pacific', start_date='2022-03-13')
next_time = t.get_next_fire_time(None, datetime(2022, 3, 13, tzinfo=t.timezone))
print(next_time)

next_time = t.get_next_fire_time(next_time, datetime(2022, 3, 14, tzinfo=t.timezone))
print(next_time)

I will look into the cron trigger logic to see what went wrong. Can you also tell me which version of APScheduler you're running?

@agronholm
Copy link
Owner

Potentially related: #529

@slipknotstrat
Copy link
Author

Thanks Agronholm.
apscheduler.version gives me '3.9.1'

@agronholm
Copy link
Owner

I added some debugging code which pointed me to the problem:

no valid value found for minute
next date: 2022-03-13 01:00:00-08:00
no valid value found for hour
next date: 2022-03-14 01:00:00-07:00

So where it should reset the lower order fields when incrementing the day of month, it somehow retains the hour as 1, therefore skipping the correct next fire time, 00:00:00.

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

No branches or pull requests

2 participants