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

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

Open
wasnertobias opened this issue Dec 8, 2023 · 10 comments

Comments

@wasnertobias
Copy link

wasnertobias commented Dec 8, 2023

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 wasnertobias changed the title Inconsistent startup behaviour on daily tasks at midnight - Docker related? Inconsistent startup behaviour on daily tasks at midnight - Timezone related Dec 8, 2023
@wasnertobias
Copy link
Author

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
Copy link
Author

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
Copy link

bschoenmaeckers commented Dec 22, 2023

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
Copy link

jsvachon2 commented Jan 17, 2024

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
Copy link
Author

wasnertobias commented Jan 17, 2024

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
Copy link

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
Copy link

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

@AiroPi
Copy link

AiroPi commented Jan 24, 2024

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

It doesn't fix the issue for me

@Masterain98
Copy link

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
Copy link

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

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

No branches or pull requests

6 participants