Skip to content Skip to sidebar Skip to footer

Invoke Celery Task From Tornado

How can someone invoke a celery task from tornado, and get the result via a callback? This post claims that someone must simply put a message via RabbitMQ and then the task shall

Solution 1:

The callback object should be a celery Task too or your code doesn't work.

You can use signals inside the task body if your callback function don't have to be a celery task.

http://docs.python.org/library/signal.html

Solution 2:

If you have the module with your tasks in the pythonpath of your tornado process a simple:

my_task.delay()

should work as long as celery is configured properly in your tornado instance. To do that when starting your server pass:

CELERY_CONFIG_MODULE=app.foo.celeryconfig

in the environment so when you do import celery, celery set up would know where your settings for this instance are.

Solution 3:

celery has callback function, you could go to http://ask.github.com/celery/userguide/tasksets.html

from celery.task import task
from celery.task.sets import subtask

@taskdefadd(x, y, callback=None):
    result = x + y

    if callback isnotNone:
        subtask(callback).delay(result)

    return result

Post a Comment for "Invoke Celery Task From Tornado"