Reputation: 10251
I am trying to retry a task that fails with the following code:
@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
This is causing the following error to be thrown:
Reject: (TypeError('__init__() takes exactly 2 arguments (3 given)',), True)
I can't what this error relates to, or how I can fix it. Am I calling the retry method in the correct way?
My celery config file looks like so:
BROKER_URL = "redis://localhost:6379/0"
CELERY_IMPORTS = ("tasks", )
CELERY_RESULT_BACKEND = "redis://localhost:6379/0"
CELERY_IGNORE_RESULT = True
Edit: Full stack trace:
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)
Upvotes: 1
Views: 1063
Reputation: 5807
You can't decorate instance methods using the @task
decorator used with regular functios.You will have to use
from celery.contrib.methods import task
instead of the regular one:
from celery import task
It might have some caveats, as it is experimental since version 3.0, please refer to this link:
http://docs.celeryproject.org/en/latest/reference/celery.contrib.methods.html
Upvotes: 1