dbader / schedule

Python job scheduling for humans.
https://schedule.readthedocs.io/
MIT License
11.62k stars 954 forks source link

Inconsistent startup behaviour on daily tasks at midnight - Timezone related #609

Open wasnertobias opened 7 months ago

wasnertobias commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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.

bschoenmaeckers commented 7 months ago

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)
jsvachon2 commented 6 months ago

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

wasnertobias commented 6 months ago

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

jsvachon2 commented 6 months ago

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

bschoenmaeckers commented 5 months ago

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

AiroPi commented 5 months ago

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

It doesn't fix the issue for me

Masterain98 commented 2 months ago

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.

MysteryAngle commented 2 months ago

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

runarsae commented 3 days ago

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.