Recently, I have been going though celery & kombu documentation as i need them integrated in one of my projects. I have a basic understanding of how this should work but documentation examples using different brokers have me confused.
Here is the scenario:
Within my application i have two views ViewA
and ViewB
both of them does some expensive processing, so i wanted to have them use celery tasks for processing. So this is what i did.
views.py
def ViewA(request):
tasks.do_task_a.apply_async(args=[a, b])
def ViewB(request):
tasks.do_task_b.apply_async(args=[a, b])
tasks.py
@task()
def do_task_a(a, b):
# Do something Expensive
@task()
def do_task_b(a, b):
# Do something Expensive here too
Until now, everything is working fine. The problem is that do_task_a
creates a txt
file on the system, which i need to use in do_task_b
. Now, in the do_task_b
method i can check for the file existence and call the tasks retry
method [which is what i am doing right now] if the file does not exist.
Here, I would rather want to take a different approach (i.e. where messaging comes in). I would want do_task_a
to send a message to do_task_b
once the file has been created instead of looping the retry method until the file is created.
I read through the documentation of celery
and kombu
and updated my settings as follows.
BROKER_URL = "django://"
CELERY_RESULT_BACKEND = "database"
CELERY_RESULT_DBURI = "sqlite:///celery"
TASK_RETRY_DELAY = 30 #Define Time in Seconds
DATABASE_ROUTERS = ['portal.db_routers.CeleryRouter']
CELERY_QUEUES = (
Queue('filecreation', exchange=exchanges.genex, routing_key='file.create'),
)
CELERY_ROUTES = ('celeryconf.routers.CeleryTaskRouter',)
and i am stuck here. don't know where to go from here.
What should i do next to make do_task_a
to broadcast a message to do_task_b
on file creation ? and what should i do to make do_task_b
receive (consume) the message and process the code further ??
Any Ideas and suggestions are welcome.