使用自定义状态时任务状态不更新
我有一个这样的任务:
@task
def test():
time.sleep(10)
test.update_state(state="PROGRESS")
time.sleep(10)
return "done"
然后我运行这个:
>>> from celery.execute import send_task
>>> t = send_task("testcelery.test")
>>> t.state
'PENDING'
>>> t.state
'PROGRESS'
我可以在工作人员中看到任务已完成:
[2011-02-19 20:18:43,851:INFO/MainProcess] 任务 testcelery.test[7598b170-2877-4d76-89a0-9bcc4c9f877e] 成功完成 20.0225799084s:“完成”
但 t.state 永远不会从“进展”更改为“成功”。我做错了什么?
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_task("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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该升级到 Celery 2.2.4(昨天发布),因为它修复了导致此问题的错误。
请参阅http://celeryq.org/docs/changelog.html
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
在我看来,CELERY_IGNORE_RESULT 设置会导致这种行为。什么是 t.ignore_result?如果是 true,则更改它或更改默认值。如果您想始终检查结果,那么更改 CELERY_IGNORE_RESULT 对我来说更有意义。但是,将其设置在每项任务上会让你的意图更加明显。
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.