python - How to switch tasks between queues in Celery -
i've got couple of tasks in tasks.py
in celery.
# should go 'math' queue @app.task def add(x,y): uuid = uuid.uuid4() result = x + y return {'id': uuid, 'result': result} # should go 'info' queue @app.task def notification(calculation): print repr(calculation)
what i'd place each of these tasks in separate celery queue , assign number of workers on each queue.
the problem don't know of way place task 1 queue within code.
so instance when add
task finishes execution need way place resulting python dictionary info
queue futher processing. how should that?
thanks in advance.
edit -clarification-
as said in comments question becomes how can worker place data retrieved queue a
queue b
.
you can try this.
wherever calling task,you can assign task queue.
add.apply_async(queue="queuename1") notification.apply_async(queue="queuename2")
by way can put tasks in seperate queue.
worker seperate queues
celery -a proj -q queuename1 -l info celery -a proj -q queuename2 -l info
but must know default
queue celery
.so if tasks without specifying queue name
goto celery
queue.so consumer celery
needed if like.
celery -a proj -q queuename1,celery -l info
for expected answer
if want pass result of 1 task another.then
result = add.apply_async(queue="queuename1") result = result.get() #this contain return value of task
then
notification.apply_async(args=[result], queue="queuename2")
Comments
Post a Comment