Reputation: 150
I have two environments
1. webserver
2. celery worker
webserver add jobs to celery message queue. but those env are separated, so can not import task function.
how to call not exist task explicitly?
ex)
# A project (web) - view.py
def view(request):
[X] task_a.delay()
[O] add_jobs("task_a", *args)
...
# B project (worker) - tasks.py
@task
def task_a:
...
Upvotes: 1
Views: 411
Reputation: 15926
Use the send_task
function to send a task to a decoupled celery project.
from celery.app import Celery
app = Celery(broker_url='the broker url of the celery instance')
app.send_task(name='myapp.mytaskname', kwargs={
'arg1': 'value1',
'arg2': 'value2',
})
Upvotes: 2