schedule icon indicating copy to clipboard operation
schedule copied to clipboard

Inconsistent startup behaviour on daily tasks at midnight - Timezone related

Open wasnertobias opened this issue 2 years ago • 11 comments

timezone_string = 'Europe/Berlin'

This does not get run on a startup schedule.every().day.at("13:05", timezone_string).do(day_rollover)

Whereas this runs on startup instantly schedule.every().day.at("00:00", timezone_string).do(day_rollover)

2023-12-08 15:16:12,838 - INFO - Scheduler started 2023-12-08 15:16:12,839 - DEBUG - Running job Job(interval=1, unit=days, do=day_rollover, args=(), kwargs={})

However, this behavior is different on different machines. I am not able to reproduce this on my Windows machine (running exactly the same version of schedule 1.2.1) in a virtual env, but I was able to reproduce this on a Linux Server, where the python application is running in a docker container (I can provide you with the Dockerfile if needed).

wasnertobias avatar Dec 08 '23 14:12 wasnertobias

Further information: This is most likely a timezone related issue. Only when scheduling the "day_rollover" task to run at "01:00" it is not running on startup, when e.g. trying "00:05" it still is running on startup!

timezone information on linux host machine: timedatectl Local time: Fri 2023-12-08 15:31:06 CET Universal time: Fri 2023-12-08 14:31:06 UTC RTC time: Fri 2023-12-08 14:31:06 Time zone: Europe/Berlin (CET, +0100) System clock synchronized: yes NTP service: active RTC in local TZ: no

timezone information in docker container: UTC date Fri Dec 8 14:33:59 UTC 2023

wasnertobias avatar Dec 08 '23 14:12 wasnertobias

It is even worse: When I use schedule.every().days.at("00:00", timezone_string).do(day_rollover)

It get's actually called every time schedule.run_pending() is called between 00:00 and 01:00, which is every second for me. So in total it gets called 3600 times instead of once.

wasnertobias avatar Dec 09 '23 08:12 wasnertobias

Having the same problem, but I'm calling it without a timeout so my job gets called 500k each day. Looks like the job is immediately scheduled again until 01:00.

schedule.every().day.at("00:30", "Europe/Amsterdam").do(run_task)
        while True:
            next_job = schedule.idle_seconds()
            delay = next_job if next_job is not None else 60
            await asyncio.sleep(delay)
            try:
                await asyncio.to_thread(schedule.run_pending)
            except BaseException as e:
                await asyncio.sleep(60)

bschoenmaeckers avatar Dec 22 '23 10:12 bschoenmaeckers

Having same issue when running inside a container under AWS ECS. Anything on a fixed schedule is not launched

schedule.every().day.at("16:50:00").do(my_task)

I tried with and without seconds. Tried with UTC and local time.. no luck

jsvachon2 avatar Jan 17 '24 15:01 jsvachon2

Having same issue when running inside a container under AWS ECS. Anything on a fixed schedule is not launched

schedule.every().day.at("16:50:00").do(my_task)

I tried with and without seconds. Tried with UTC and local time.. no luck

I ended up changing libraries as I did not get it working. Recommend the following when it comes to timezones: https://digon.io/hyd/project/scheduler/t/master/pages/examples/timezones.html

wasnertobias avatar Jan 17 '24 17:01 wasnertobias

Having same issue when running inside a container under AWS ECS. Anything on a fixed schedule is not launched

schedule.every().day.at("16:50:00").do(my_task)

I tried with and without seconds. Tried with UTC and local time.. no luck

I ended up changing libraries as I did not get it working. Recommend the following when it comes to timezones: https://digon.io/hyd/project/scheduler/t/master/pages/examples/timezones.html

Thanks for sharing

jsvachon2 avatar Jan 17 '24 18:01 jsvachon2

Current master fixed my issue, so a new release could help others as well.

bschoenmaeckers avatar Jan 23 '24 08:01 bschoenmaeckers

Current master fixed my issue, so a new release could help others as well.

It doesn't fix the issue for me

AiroPi avatar Jan 24 '24 06:01 AiroPi

It is even worse: When I use schedule.every().days.at("00:00", timezone_string).do(day_rollover)

It get's actually called every time schedule.run_pending() is called between 00:00 and 01:00, which is every second for me. So in total it gets called 3600 times instead of once.

I got the exact same issue; removing the time zone and setting it in the Docker container environment is the workaround in my case.

Masterain98 avatar Apr 22 '24 04:04 Masterain98

It is even worse: When I use schedule.every().days.at("00:00", timezone_string).do(day_rollover)

It get's actually called every time schedule.run_pending() is called between 00:00 and 01:00, which is every second for me. So in total it gets called 3600 times instead of once.

same issue for me, using version is: 1.2.1

MysteryAngle avatar May 01 '24 21:05 MysteryAngle

It is even worse: When I use schedule.every().days.at("00:00", timezone_string).do(day_rollover)

It get's actually called every time schedule.run_pending() is called between 00:00 and 01:00, which is every second for me. So in total it gets called 3600 times instead of once.

Same issue for me as well. Version 1.2.2.

runarsae avatar Jul 16 '24 12:07 runarsae