芹菜 - 任务重试导致奇怪的错误

时间:2013-12-16 21:00:57

标签: python celery

我正在尝试使用以下代码重试失败的任务:

@task(bind=True)
def update_listing(self, listing_object, retailer):
    try:
        listing = _update_listing(listing_object, retailer)
    except Exception as exc:
        raise self.retry(exc=exc)
    return listing

这会导致抛出以下错误:

Reject: (TypeError('__init__() takes exactly 2 arguments (3 given)',), True)

我不能解决这个错误,或者我如何解决它。我是否以正确的方式调用重试方法?

我的芹菜配置文件如下所示:

BROKER_URL = "redis://localhost:6379/0"
CELERY_IMPORTS = ("tasks", )
CELERY_RESULT_BACKEND = "redis://localhost:6379/0"   
CELERY_IGNORE_RESULT = True

编辑:完整堆栈跟踪:

Traceback (most recent call last):
  File "/home/my-project/venv/local/lib/python2.7/site-packages/celery/app/trace.py", line 218, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/my-project/venv/local/lib/python2.7/site-packages/celery/app/trace.py", line 398, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/my-project/tasks.py", line 156, in update_listing
    raise self.retry(exc=exc)
  File "/home/my-project/venv/local/lib/python2.7/site-packages/celery/app/task.py", line 666, in retry
    raise Reject(exc, requeue=True)
Reject: (TypeError('__init__() takes exactly 2 arguments (3 given)',), True)

1 个答案:

答案 0 :(得分:1)

你不能使用常规功能使用的@task装饰器来装饰实例方法。你将不得不使用

from celery.contrib.methods import task

而不是常规的:

from celery import task

它可能有一些警告,因为它是3.0版以来的实验,请参考此链接:

http://docs.celeryproject.org/en/latest/reference/celery.contrib.methods.html