procrastinate icon indicating copy to clipboard operation
procrastinate copied to clipboard

Setting timezone for periodic task

Open dreackm opened this issue 2 months ago • 6 comments

I have a periodic task that's supposed to run every 10 seconds of every weekday from 8 am to 5pm. Its cron expression is thus : * 8-17 * * 1-5 */10. I did'nt realize until today that this will run in UTC while I am in Africa/Blantyre (which is 2 hours ahead). To run it in the time I expect, I am simply specifying the hour segment as UTC, i.e., 6-15.

With the native crontab, I could specify which timezone a particular entry should run in with CRON_TZ environment variable. How do I do something similar in this case?

dreackm avatar Nov 05 '25 06:11 dreackm

I'd say this is something we should see with Croniter.

Also... I just saw that croniter is deprecated :( https://pypi.org/project/croniter/

Edit: seems it's been adopted by Pallet and it's safe. So back to: we should look at how Croniter supports timezones.

ewjoachim avatar Nov 05 '25 10:11 ewjoachim

Looks like setting a date with the correct timezone here would do the trick ? https://github.com/procrastinate-org/procrastinate/blob/main/procrastinate/periodic.py#L41 We could accept a timezone argument and propagate it. Would you like to do the PR ?

ewjoachim avatar Nov 05 '25 11:11 ewjoachim

My two cents as a maintainer, since I'm using croniter as well. I explicitly blocked all support for timezones. Croniter has had a ton of timezone bugs (https://github.com/pallets-eco/croniter/issues?q=timezone) and has a DST bug right now. I ended up just adding a visible disclaimer and tell users to handle it themselves.

Image

TkTech avatar Nov 05 '25 12:11 TkTech

Oh good to know ! I wonder if there's a way to transparently use the thing without taking responsibility, for example: accepting croniter objects instead of a cron definition. This way, if there's bugs, we limit the risk that it could be in procrastinate.

I'm not even sure I know how it should react to dst folds.

ewjoachim avatar Nov 05 '25 19:11 ewjoachim

While @TkTech's concern is justified, it's important to note that the DST issues in croniter v6.0.0 have been fixed in 6.1.0rc1.

dreackm avatar Nov 05 '25 20:11 dreackm

@ewjoachim, I think as long as users are aware of the issues that may arise when using timezone other than UTC, it shouldn't really be a concern for procrastinate.

dreackm avatar Nov 05 '25 20:11 dreackm