question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Daylight saving on interval trigger

See original GitHub issue

Hello,

We observed an issue on during the daylight saving clock on Europ/Brussels TZ during the night of 30 March and 31 March. After this time every schedule is executed with 1 hour of delay.

We thing it’s an issue on the interval trigger (the cron trigger is already reported on your website). Mabe it is a behavior expected. But we want to have more information about it.

Test

We did a simple test during in order to tackel the issue:

import pytz
import datetime

from apscheduler.schedulers.background import BackgroundScheduler

def task():
	print("TASK EXECUTED")

scheduler = BackgroundScheduler()

scheduler.add_job(task, 'interval',
	start_date=datetime.datetime(2019, 3, 26, 16, 0, 0),
	days=7
)
scheduler.add_job(task, 'interval',
	start_date=datetime.datetime(2019, 4, 2, 17, 0, 0),
	days=7
)
scheduler.add_job(task, 'interval',
	start_date=datetime.datetime(2019, 4, 2, 20, 0, 0),
	days=7
)

scheduler.start()
scheduler.print_jobs()

Expected Behavior

output expected:

Jobstore default:
    task (trigger: interval[7 days, 0:00:00], next run at: 2019-04-02 16:00:00 CEST)
    task (trigger: interval[7 days, 0:00:00], next run at: 2019-04-02 17:00:00 CEST)
    task (trigger: interval[7 days, 0:00:00], next run at: 2019-04-02 20:00:00 CEST)

Where we shedule at 16:00.

Current Behavior

output expected:

Jobstore default:
    task (trigger: interval[7 days, 0:00:00], next run at: 2019-04-02 17:00:00 CEST)
    task (trigger: interval[7 days, 0:00:00], next run at: 2019-04-02 17:00:00 CEST)
    task (trigger: interval[7 days, 0:00:00], next run at: 2019-04-02 20:00:00 CEST)

Where we shedule at 17:00 and we expect 16:00

Solution (path)

The path we made now, it’s changing the method get_next_fire_time in trigger/interval.py

Adding

next_fire_time = next_fire_time.tzinfo.localize(next_fire_time.replace(tzinfo=None))

and it become like this:

 def get_next_fire_time(self, previous_fire_time, now):
        if previous_fire_time:
            next_fire_time = previous_fire_time + self.interval
        elif self.start_date > now:
            next_fire_time = self.start_date
        else:
            timediff_seconds = timedelta_seconds(now - self.start_date)
            next_interval_num = int(ceil(timediff_seconds / self.interval_length))
            next_fire_time = self.start_date + self.interval * next_interval_num
            # PATCH MADE
            next_fire_time = next_fire_time.tzinfo.localize(next_fire_time.replace(tzinfo=None))

        if self.jitter is not None:
            next_fire_time = self._apply_jitter(next_fire_time, self.jitter, now)

        if not self.end_date or next_fire_time <= self.end_date:
            return self.timezone.normalize(next_fire_time)

So we would like to have your expetise in order to know if this patch is good or we made a mistake ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
agronholmcommented, Jun 11, 2019

The interval trigger is documented to fire on constant intervals. If you want something else, you will need a different kind of trigger. It sounds like the calendar interval trigger is what you want. I will integrate that in a future version of APScheduler, but for now you can find the base code here. It will need some adaptation on your part to work with APScheduler, but the code passes its test suite in its own repository.

0reactions
sdefauwcommented, Jun 11, 2019

Okay, thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CalendarIntervalTrigger (Quartz Enterprise Job Scheduler 2.2 ...
But after the daylight saving transition occurs, the trigger may start firing at 8:00 am every other day.
Read more >
How daylight savings time affects scheduled triggers - HighBond
Triggers running on a scheduled frequency automatically switch between standard time (ST) and daylight savings time (DST) according to the trigger's time zone. ......
Read more >
Time Zone and Daylight Saving Support for Schedule Trigger
Create new trigger and select Schedule for type · Specify the start date in the desired time zone (e.g. 9AM 2020-10-30 Pacific Time,...
Read more >
Daylight Saving Time Rules | NIST
We advance our clocks ahead one hour at the beginning of DST, and move them back one hour ("spring forward, fall back") when...
Read more >
Daylight savings time change affecting Task schedule
The Day interval schedules the next run 24 hours from the previous scheduled time, depending on the settings. This can lead to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found