I have a task like this:
@task
def test():
time.sleep(10)
test.update_state(state="PROGRESS")
time.sleep(10)
return "done"
I then run this:
>>> from celery.execute import send_task
>>> t = send_开发者_如何学Pythontask("testcelery.test")
>>> t.state
'PENDING'
>>> t.state
'PROGRESS'
I can see in the worker that the task has completed:
[2011-02-19 20:18:43,851: INFO/MainProcess] Task testcelery.test[7598b170-2877-4d76-89a0-9bcc4c9f877e] succeeded in 20.0225799084s: 'done'
But t.state never changes from PROGRESS to SUCCESS. What am I doing wrong?
You should upgrade to Celery 2.2.4 (released yesterday) as it fixes the bug that causes this.
See http://celeryq.org/docs/changelog.html
It looks to me like CELERY_IGNORE_RESULT set would cause this behavior. What is t.ignore_result? If it is true then either change it or change the default. If you want to always inspect the result then changing CELERY_IGNORE_RESULT makes more sense to me. But then setting it on every task would make your intentions more obvious.
精彩评论