Celery Task with countdown

celery, python

Solution

The problem is likely not being in the right timezone. By setting `countdown=20` you might be telling Celery to execute the task 20 seconds after 3 hours ago.

I suggest using the pytz library to tell Celery to start the task at the right time:

from datetime import datetime, timedelta
from pytz import timezone

# Set timezone: http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
my_tz = timezone('US/Eastern')

DemoTask.apply_async(eta=my_tz.localize(datetime.now()) + timedelta(seconds=20))

Or even easier if you are using Django (and have set `TIME_ZONE` in `settings.py`):

from datetime import timedelta
from django.utils.timezone import now

DemoTask.apply_async(eta=now() + timedelta(seconds=20))

Problem

I am using Celery 2.5.1 and I am trying to use `countdown` to run the task after 20 seconds, but it gets executed immediately. I am using it as: ``` DemoTask.apply_async(countdown = 20) ``` Am I missing something here?

Original source