2

I want to create multiple celery tasks from the same function, and they will differ in the parameters that I pass to the task decorator. Let's say I want to set different timeouts for paid and free account in my system.

I was expecting that applying the task decorator in the following way will do the trick:

def _update(x, y):
    ...    

update_free = task(soft_time_limit=300, time_limit=305)(_update)

update_paid = task(time_limit=1800)(_update)

But I see in the log that neither update_paid nor update_free are registered as tasks. Instead for some reason _update is registered as a task.

I don't why celery/django-celery does this, seem to be quite obscure to me. Does anyone have any idea how to fix this? Thanks.

1 Answer 1

2

Celery's task decorators uses the decorated function's name when registering the task, and this name is set to "_update" when the function is defined:

>>> def _update(x, y):
...     pass
... 
>>> _update.__name__
  > '_update'
>>> update2 = _update
>>> update2.__name__
  > '_update'

You can specify the name of the task in the decorator though:

update_free = task(name='update_free', soft_time_limit=300, time_limit=305)(_update)
update_paid = task(name='update_paid', time_limit=1800)(_update)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.