Reputation: 2069
I am switching task naming scheme. There are parts of the code which still use old names, and some which use new names. So, my question is: what is the proper way of aliasing Celery tasks?
@task
def new_task_name():
pass
old_task_name = new_task_name # doesn't work
app.tasks['old_task_name'] = new_task_name # still doesn't work
I get error similar to this:
Received unregistered task of type 'app.tasks.old_task_name'
UPDATE:
My current solution is forwarding tasks. But I still hope there's a cleaner approach:
@task
def old_task_name():
new_task_name.delay()
Upvotes: 2
Views: 546
Reputation: 4241
I found this to be the "easiest" way:
from copy import deepcopy
@app.task(bind=True, base=MyTask)
def new_task_name(self, *args, **kwargs):
pass
# Backwards compatibility, old task name as an alias
OldTask = deepcopy(new_task_name)
OldTask.name = "old_task_name"
app.register_task(task=OldTask)
Upvotes: 0
Reputation: 54249
This question is ancient but a more direct way to do this is:
@task(name='old-name')
def old_task_name(*args, **kwargs):
return new_task_name(*args, **kwargs)
Celery tasks can still be called as normal methods too.
Upvotes: 0