I am writing a small test task for django-celery, in which I would like to set a custom state (and some data, but let’s start with a custom state first).
I use django as the messaging backend. My version of python is 2.6.
Here’s the content of tasks.py
import time
from djcelery import celery
@celery.task
def generate():
generate.update_state(state="PROGRESS")
time.sleep(10)
return True
And here’s what happens when I give it a try:
>>> import tasks
>>> result = tasks.generate.delay()
>>> result
<AsyncResult: f72574aa-f8c5-49dc-89d4-47d2012a4d6d>
# status and state are the same, but just to make sure
>>> result.status
u'PENDING'
>>> result.state
u'PENDING'
>>> result.result
# empty, as in None
# wait a few seconds
>>> result.status
u'SUCCESS'
>>> result.state
u'SUCCESS'
>>> result.result
True
I can’t figure out why the state is PENDING while it should be PROGRESS. Any idea?
I’ve already looked at the documentation, and here’s the relevant link: http://docs.celeryproject.org/en/latest/userguide/tasks.html#custom-states
I do the exact same thing (minus the meta, but I also tried without success), so it should work.
UPDATE: I found out why, looks like you have to restart the celery daemon whenever you update your tasks so that the changes are taken into account.
I found out why, looks like you have to restart the celery daemon whenever you update your tasks so that the changes are taken into account.