0

Now I using django-celery to send scheduled emails to user. it works fine if all users in same timezone. But if a user in different timezone, he will get the not in right time.

For example, I scheduled an email send to user a, user b at 8am every day with CrontabSchedule, server is GMT time, user a is GMT, user b is GMT+1, user a will get that email at 8am but user b will get it at 9am.

How can I schedule tasks for different timezones with celery?

2
  • So user B has an Interface to set the time he wants to receive the email? Commented Dec 11, 2013 at 6:40
  • @kanu Yeah, we know all users' timezones Commented Dec 11, 2013 at 6:42

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.