python - Celery periodic tasks timezones -


I have some periodic tasks that need to be run on the first day of the month at midnight, but the customer's time zone I am trying to keep everything in UTC, so I have

  CELERY_ENABLE_UTC = true  

So if I have many tasks, then everyone Need to run at midnight in a specific time zone, what is the most obvious way to do this with Celery? For example, run these 2 tasks in your respective timezones in midnight?

  Customers # 1, this customer needs to run on # 2 midnight EST (US / Eastern) schedule1 = crontab (DAY_OF_MONTH = 1, hours = 0, min = 0) This needs to be run on midnight PST (US / Pacific) schedule1 = crontab (DAY_OF_MONTH = 1, hour = 0, minute = 0)  

< Div class = "text" itemprop = "text">

crontab () function only accepts minutes , hours , DAY_OF_WEEK , day_off_mon , day_of_year and month_of_year As Ramitr you want to run a job at midnight for the various time zones to calculate the time for them to set the UTC (or any other default time zone celery config). Import time from datetime import date from pytz

  get_utc_for_midnight_in_timezone (tzstring): local_midnight = datetime (2000, 1, 1, 0, 0, 0, = time zone tzinfo (tzstring)) UTC Return to '{DAY_OF_MONTH}: Utc.day,' hour ': utc.hour,' minute ': utc.minute}  

You can use the above function like this:

  client1_schedule = crontab (** get_utc_for_midnight_in_timezone ('US / Pacific')) client2_schedule = crontab (** get_utc_for_midnight_in_timezone ('America / Eastern' ))  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -