-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Hi everyone,
I found no way to customize the timezone used by Celery and would like to propose an improvement.
This would be very useful, since the periodic: crontab
feature defaults to UTC timezone, making the cron definition "harder to understand".
Explaining the functionality in Celery
By Celery 5.2.7 documentation, timezones should be implemented by configuring the following parameters when creating the Celery app: enable_utc
and timezone
.
As explained there, enable_utc
defaults to true, and if true uses UTC as the default timezone for Celery. If set to false, Celery uses the system's timezone (in case of docker / docker-compose, it should be easily set by the TZ environment variable).
Likewise, when timezone
is set to an appropriate pytz value, Celery uses it.
Changes to celery-director
- Add an optional environment variable such as
DIRECTOR_TZ
orDIRECTOR_ENABLE_UTC
- Remove
webserver
UTC adjustment - Modify file by changing the lines:
...
# Celery configuration
self.CELERY_CONF = {
"task_always_eager": False,
"broker_url": env.str("DIRECTOR_BROKER_URI", "redis://localhost:6379/0"),
"result_backend": env.str(
"DIRECTOR_RESULT_BACKEND_URI", "redis://localhost:6379/1"
),
"broker_transport_options": {"master_name": "director"},
}
...
About the pull request
I'm able and willing to create this modification and help as needed.
What I need is guidance on whether or not this should be done. And if so, how it should be done. Both enable_utc
and timezone
allow for the timezone to be customized, but I have doubts about which one is better to use.
My initial idea was to create only DIRECTOR_TZ
and modify the code to check if it is set. And if not, default to UTC (default value in Celery).
Anyways,
Thanks for this amazing project!
Best regards