使用 Django-Celery 重试任务 - Django/Celery
我在重试任务时遇到问题,这是测试任务的样子,
from celery.decorators import task
@task()
def add(x, y):
if not x or not y:
raise Exception("test error")
return x+y
我找不到任何有关如何重试装饰任务的文档,我发现的只是:
self.retry(x,y, exc=exception, countdown=30)
这似乎不适用于我的情况该方法没有传递 self 变量。
编辑:
我现在尝试以下操作无效:
from celery.decorators import task
@task()
def add(x, y):
if not x or not y:
try:
raise Exception("test error")
except Exception, e:
add.retry([x, y], exc=e, countdown=30)
return x+y
我收到以下错误:
TypeError(“重试的 kwargs 参数不能为空。任务必须接受 **kwargs,请参阅
I'm having problems retrying tasks, here is what a test task looks like
from celery.decorators import task
@task()
def add(x, y):
if not x or not y:
raise Exception("test error")
return x+y
I cannot find any documentation what-so-ever on how to retry decorated tasks, all I found was this:
self.retry(x,y, exc=exception, countdown=30)
which doesn't seem to work with my case as there is not self
variable being passed from the method.
Edit:
I'm trying the following now to no avail:
from celery.decorators import task
@task()
def add(x, y):
if not x or not y:
try:
raise Exception("test error")
except Exception, e:
add.retry([x, y], exc=e, countdown=30)
return x+y
I get the following error:
TypeError("kwargs argument to retries can't be empty. Task must accept **kwargs, see http://bit.ly/cAx3Bg",)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在装饰器中设置重试参数:
You can set your retry parameters in the decorator:
该任务需要接受关键字参数,它们用于传递有关重试计数的信息。我认为代码应该是这样的:
**kwargs
需要添加到add
函数的签名中,并作为kwargs=kwargs
传递> 调用重试时。注意:此样式随着 celery 2.2 的发布而被弃用。
The task needs to accept keyword arguments, they are used to pass information amongst other about the retry count. I think the code should look like this:
**kwargs
need to be added to the signature of theadd
function, and passed askwargs=kwargs
when calling retry.Note: this style was deprecated with the release of celery 2.2.