Non-blocking Celery client for Tornado
Latest commit b4aeaf7 Dec 26, 2016 @mher committed on GitHub Merge pull request #69 from kardaj/patch-1
Update AUTHORS #68
Failed to load latest commit information.
docs fix typo in docs Oct 30, 2014
examples Cleanup Oct 4, 2014
requirements Add requirements for docs Apr 20, 2014
tcelery fix issues #53, #66: celery 4.0+ support Dec 25, 2016
tests update tests and docs Oct 3, 2014
.gitignore Add .gitignore Apr 5, 2014
AUTHORS Update AUTHORS #68 Dec 26, 2016
LICENSE Adds license Sep 29, 2012 Adds Apr 23, 2013
README.rst Remove downloads badge Dec 26, 2016 Adds paver script Apr 20, 2013 Updated dependency Jan 29, 2015


Celery integration with Tornado

tornado-celery is a non-blocking Celery client for Tornado web framework


Calling Celery tasks from Tornado RequestHandler:

from tornado import gen, web
import tcelery, tasks


class AsyncHandler(web.RequestHandler):
    def get(self):
        tasks.echo.apply_async(args=['Hello world!'], callback=self.on_result)

    def on_result(self, response):

Calling tasks with generator-based interface:

class GenAsyncHandler(web.RequestHandler):
    def get(self):
        response = yield gen.Task(tasks.sleep.apply_async, args=[3])

NOTE: Currently callbacks only work with AMQP and Redis backends. To use the Redis backend, you must install tornado-redis.

tornado-celery can be launched as a web server:

$ cd tornado-celery
$ python -m tcelery --port=8888 --app=examples.tasks --address=

Execute a task asynchronously:

$ curl -X POST -d '{"args":["hello"]}' http://localhost:8888/apply-async/examples.tasks.echo/
{"task-id": "a24c9e38-4976-426a-83d6-6b10b4de7ab1", "state": "PENDING"}

Get the result:

$ curl http://localhost:8888/tasks/result/a24c9e38-4976-426a-83d6-6b10b4de7ab1/
{"task-id": "a24c9e38-4976-426a-83d6-6b10b4de7ab1", "state": "SUCCESS", "result": "hello"}

Execute a task and get the result:

$ curl -X POST -d '{"args":[1,2]}' http://localhost:8888/apply/examples.tasks.add/
{"task-id": "fe3cc5a5-d11b-4b17-a6e2-e7fd2fba7ec6", "state": "SUCCESS", "result": 3}

Execute a task with timeout:

$ curl -X POST -d '{"args":[5],"timeout":1}' http://localhost:8888/apply/examples.tasks.sleep/
{"task-id": "9ca78e26-bbb2-404c-b3bb-bc1c63cbdf41", "state": "REVOKED"}


To install, simply:

$ pip install tornado-celery


Documentation is available at Read the Docs

Running the Tests

To run the tests for the AMQP backend:

$ python examples/ worker
$ cd examples && python -m tcelery -A tasks
$ python tests/

To run the tests for the Redis backend, first make sure redis is running, then:

$ CELERY_RESULT_BACKEND=redis:// python examples/ worker
$ cd examples && CELERY_RESULT_BACKEND=redis:// python -m tcelery -A tasks
$ python tests/