Call Django Celery Task By Name
I need to call a celery task (in tasks.py) from models.py, the only problem is, tasks.py imports models.py, so I can't import tasks.py from models.py. Is there some way to call a c
Solution 1:
Yes, there is.
You can use:
from celery.execute import send_task
send_task('my_task', [], kwargs)
Be sure that you task function has a name:
from celery import task
@task(name='my_task')defmy_task():
...
Hope it helps!
Solution 2:
In Celery 3+:
from celery importCeleryapp= Celery()
app.send_task('my_task', [], kwargs)
Post a Comment for "Call Django Celery Task By Name"