0
>>> def elp(min):
...     when = datetime.now() + timedelta(minutes=min)
...     print when
...     r = add.apply_async(args=[500,500],eta=when)
...     start = time.time()
...     r.get()
...     end = time.time()
...     elapsed = end-start
...     print elapsed
...
>>> elp(10)

2014-11-08 04:38:01.745000
1.00200009346

Where as when using countdown

>>> def elp_countdown(min):
...     r = add.apply_async(args=[500,500],countdown=(min*60))
...     start = time.time()
...     r.get()
...     end = time.time()
...     elapsed = end-start
...     print elapsed
...
>>> elp_countdown(0.5)
30.1380000114

Why does the task gets executed faster than its suppose when using eta?

my add task is as follows,

@task()
def add(x, y):
    return x + y

Celery verison: 3.1.16 (Cipater)

1
  • You need to get start time before you apply the tasks. Commented Nov 8, 2014 at 9:42

1 Answer 1

1

So after some research and lot's of reading, it turns out that I needed to pass a utc datetime to celery, since it's time zone is configured by default to be in UTC.

In case anyone is wondering, changing to this:

when = datetime.utcnow() + timedelta(minutes=min)

instead of

when = datetime.now() + timedelta(minutes=min)

will make it work as it should.

Sign up to request clarification or add additional context in comments.

2 Comments

You posted two times the exact same line. So what did you change?
if you are using when = datetime.now() + timedelta(minutes=min) then celery executes your job immediately. Always use datetime.utcnow()

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.