[Answer]-Celery for different timezones

1👍

When user B has his timezone set to “Europe/Vienna” he will be GMT+1 in winter and GMT+2 in summer.
A daily delivery time needs to be combined with a date to know when in UTC it needs to be sent.

A solution might be a daily script that calculates the delivery datetime for each user and sends celery tasks with the correct dateime as ETA.
(i hope the send_task still works that way)

from pytz import timezone, utc
from datetime import date, datetime
from celery.execute import send_task

def daily_delivery(delivery_time, delivery_timezone, task_name, task_args, task_kwargs):

    tz = timezone(delivery_timezone)
    today = date.today()
    local_delivery = datetime.combine(today, delivery_time)
    utc_delivery = utc.normalize(tz.localize(local_delivery).astimezone(utc))
    return send_task(task_name, task, args=task_args, kwargs=task_kwargs, eta=utc_delivery)
👤kanu

Leave a comment