芹菜到期-上升异常 [英] Celery expires - Rise exception
本文介绍了芹菜到期-上升异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有关过期的文档链接
# Task expires after one minute from now.
add.apply_async(args=[10, 10], expires=60)
我使用:
from tasks import add
result = add.apply_async(args=[10, 10], expires=6000)
printus(result)
def printus(result):
print (result) #task id
print (result.ready()) # returns True if the task has finished processing.
print (result.result) # task is not ready, so no return value yet.
print (result.get()) # Waits until the task is done and returns the retval.
print (result.result) # direct access to result, doesn't re-raise errors.
print (result.successful()) # returns True if the task didn't end in failure.)
tasks.py
from celery.task import task
@task
def add(x, y):
return x + y
芹菜:
[2012-03-21 19:50:03,012: WARNING/MainProcess] Skipping revoked task: tasks.add[4ffcff91-b12b-4bce-8d47-159314759859]
在控制台中:
4ffcff91-b12b-4bce-8d47-159314759859
True
Traceback (most recent call last):
File "/home/echeg/Dropbox/my_py/opoveshun/tests/celery/run_task.py", line 53, in <module>
tr.countdown()
File "/home/echeg/Dropbox/my_py/opoveshun/tests/celery/run_task.py", line 26, in countdown
self.printus(result)
File "/home/echeg/Dropbox/my_py/opoveshun/tests/celery/run_task.py", line 48, in printus
print (result.get()) # Waits until the task is done and returns the retval.
File "/usr/local/lib/python2.7/dist-packages/celery/result.py", line 95, in get
interval=interval)
File "/usr/local/lib/python2.7/dist-packages/celery/backends/amqp.py", line 144, in wait_for
raise self.exception_to_python(meta["result"])
celery.exceptions.TaskRevokedError
为什么会出现异常?结果尚未过期
Why do I get an exception? The result has not expired
如果我使用:
result = add.apply_async(args=[10, 10])
一切正常
226107de-f739-4860-83bc-d843f17a257e
False
None
20
20
True
推荐答案
celeryd认为您的任务已过期:
celeryd thinks your task has expired:
[2012-03-21 19:50:03,012: WARNING/MainProcess] Skipping revoked task: tasks.add[4ffcff91-b12b-4bce-8d47-159314759859]
当工人拿起过期任务时,它将其撤销而不执行.检查您的时区设置?我遇到了一个相反的问题:任务应该在什么时候到期.这对我来说是固定的:
When an expired task is picked up by a worker, it revokes it without executing. Check your timezone settings? I had the inverse problem: tasks weren't expiring when they should have. This fixed it for me:
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'Etc/UTC'
这篇关于芹菜到期-上升异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文