I’m having a task that looks like this
from mybasetask_module import MyBaseTask
@task(base=MyBaseTask)
@my_custom_decorator
def my_task(*args, **kwargs):
pass
and my base task looks like this
from celery import task, Task
class MyBaseTask(Task):
abstract = True
default_retry_delay = 10
max_retries = 3
acks_late = True
The problem I’m running into is that the celery worker is registering the task with the name
'mybasetask_module.__inner'
The task is registerd fine (which is the package+module+function) when I remove @my_custom_decorator from the task or if I provide an explicit name to the task like this
from mybasetask_module import MyBaseTask
@task(base=MyBaseTask, name='an_explicit_task_name')
@my_custom_decorator
def my_task(*args, **kwargs):
pass
Is this behavior expected? Do I need to do something so that my tasks are registered with the default auto registered name in the first case when I have multiple decorators but no explicit task name?
Thanks,
Use the
functools.wraps()decorator to ensure that the wrapper returned bymy_custom_decoratorhas the correct name:The task name is taken from the function call that the
taskdecorator wraps, but by inserting a decorator in between, you gavetaskyour__innerwrapping function instead. Thefunctools.wraps()decorator copies all the necessary metadata over fromfuncto the wrapper so thattask()can pick up the proper name.