introduction.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. :Version: 3.0.0rc5 (Chiastic Slide)
  2. :Web: http://celeryproject.org/
  3. :Download: http://pypi.python.org/pypi/celery/
  4. :Source: http://github.com/celery/celery/
  5. :Keywords: task queue, job queue, asynchronous, rabbitmq, amqp, redis,
  6. python, webhooks, queue, distributed
  7. --
  8. .. contents::
  9. :local:
  10. .. _celery-synopsis:
  11. Synopsis
  12. ========
  13. Celery is an open source asynchronous task queue/job queue based on
  14. distributed message passing. It is focused on real-time operation,
  15. but supports scheduling as well.
  16. The execution units, called tasks, are executed concurrently on one or
  17. more worker nodes using multiprocessing, `Eventlet`_ or `gevent`_. Tasks can
  18. execute asynchronously (in the background) or synchronously
  19. (wait until ready).
  20. Celery is used in production systems to process millions of tasks every hour.
  21. Celery is written in Python, but the protocol can be implemented in any
  22. language. It can also `operate with other languages using webhooks`_.
  23. There's also `RCelery` for the Ruby programming language, and a `PHP client`.
  24. The recommended message broker is `RabbitMQ`_, but support for
  25. `Redis`_, `MongoDB`_, `Beanstalk`_, `Amazon SQS`_, `CouchDB`_ and
  26. databases (using `SQLAlchemy`_ or the `Django ORM`_) is also available.
  27. Celery is easy to integrate with web frameworks, some of which even have
  28. integration packages:
  29. +--------------------+------------------------+
  30. | `Django`_ | `django-celery`_ |
  31. +--------------------+------------------------+
  32. | `Pyramid`_ | `pyramid_celery`_ |
  33. +--------------------+------------------------+
  34. | `Pylons`_ | `celery-pylons`_ |
  35. +--------------------+------------------------+
  36. | `Flask`_ | `flask-celery`_ |
  37. +--------------------+------------------------+
  38. | `web2py`_ | `web2py-celery`_ |
  39. +--------------------+------------------------+
  40. | `Tornado`_ | `tornado-celery`_ |
  41. +--------------------+------------------------+
  42. .. _`RCelery`: http://leapfrogdevelopment.github.com/rcelery/
  43. .. _`PHP client`: https://github.com/gjedeer/celery-php
  44. .. _`RabbitMQ`: http://www.rabbitmq.com/
  45. .. _`Redis`: http://code.google.com/p/redis/
  46. .. _`SQLAlchemy`: http://www.sqlalchemy.org/
  47. .. _`Django`: http://djangoproject.com/
  48. .. _`Django ORM`: http://djangoproject.com/
  49. .. _`Memcached`: http://memcached.org/
  50. .. _`Eventlet`: http://eventlet.net/
  51. .. _`gevent`: http://gevent.org/
  52. .. _`Beanstalk`: http://kr.github.com/beanstalkd/
  53. .. _`MongoDB`: http://mongodb.org/
  54. .. _`CouchDB`: http://couchdb.apache.org/
  55. .. _`Amazon SQS`: http://aws.amazon.com/sqs/
  56. .. _`Pylons`: http://pylonshq.com/
  57. .. _`Flask`: http://flask.pocoo.org/
  58. .. _`web2py`: http://web2py.com/
  59. .. _`Bottle`: http://bottlepy.org/
  60. .. _`Pyramid`: http://docs.pylonsproject.org/en/latest/docs/pyramid.html
  61. .. _`pyramid_celery`: http://pypi.python.org/pypi/pyramid_celery/
  62. .. _`django-celery`: http://pypi.python.org/pypi/django-celery
  63. .. _`celery-pylons`: http://pypi.python.org/pypi/celery-pylons
  64. .. _`flask-celery`: http://github.com/ask/flask-celery/
  65. .. _`web2py-celery`: http://code.google.com/p/web2py-celery/
  66. .. _`Tornado`: http://www.tornadoweb.org/
  67. .. _`tornado-celery`: http://github.com/mher/tornado-celery/
  68. .. _`operate with other languages using webhooks`:
  69. http://celery.github.com/celery/userguide/remote-tasks.html
  70. .. _`limited support`:
  71. http://kombu.readthedocs.org/en/latest/introduction.html#transport-comparison
  72. .. _celery-overview:
  73. Overview
  74. ========
  75. This is a high level overview of the architecture.
  76. .. image:: http://cloud.github.com/downloads/celery/celery/Celery-Overview-v4.jpg
  77. The broker delivers tasks to the worker instances.
  78. A worker instance is started by running the `celery worker` program.
  79. You can have many networked machines running worker instances, forming a
  80. cluster, or you can run everything on a single machine.
  81. The return value of the task can be stored for later retrieval,
  82. and the progress of the task can be tracked (called the task's *state*).
  83. .. _celery-example:
  84. Example
  85. =======
  86. You probably want to see some code by now, this is the simplest
  87. Celery application you can make, you can put it in a module
  88. named ``tasks.py``:
  89. .. code-block:: python
  90. from celery import Celery
  91. celery = Celery(broker='amqp://guest@localhost://')
  92. @celery.task()
  93. def add(x, y):
  94. return x + y
  95. You can execute the task in the background, or wait for it to finish::
  96. >>> result = add.delay(4, 4)
  97. >>> result.get(timeout=1) # wait for and return the result
  98. 8
  99. But before the task can execute you need to start a worker::
  100. $ celery --app=tasks worker -l info
  101. .. _celery-features:
  102. Features
  103. ========
  104. +-----------------+----------------------------------------------------+
  105. | Messaging | Supported brokers include `RabbitMQ`_, `Redis`_, |
  106. | | `MongoDB`_, `Beanstalk`_, SQL databases, |
  107. | | Amazon SQS and more. |
  108. +-----------------+----------------------------------------------------+
  109. | Fault-tolerant | Excellent configurable error recovery when using |
  110. | | `RabbitMQ`, ensures your tasks are never lost. |
  111. +-----------------+----------------------------------------------------+
  112. | Distributed | Runs on one or more machines. Supports |
  113. | | broker `clustering`_ and `HA`_ when used in |
  114. | | combination with `RabbitMQ`_. You can set up new |
  115. | | workers without central configuration (e.g. use |
  116. | | your grandma's laptop to help if the queue is |
  117. | | temporarily congested). |
  118. +-----------------+----------------------------------------------------+
  119. | Concurrency | Concurrency is achieved by using multiprocessing, |
  120. | | `Eventlet`_, `gevent` or a mix of these. |
  121. +-----------------+----------------------------------------------------+
  122. | Scheduling | Supports recurring tasks like cron, or specifying |
  123. | | an exact date or countdown for when after the task |
  124. | | should be executed. |
  125. +-----------------+----------------------------------------------------+
  126. | Latency | Low latency means you are able to execute tasks |
  127. | | *while the user is waiting*. |
  128. +-----------------+----------------------------------------------------+
  129. | Return Values | Task return values can be saved to the selected |
  130. | | result store backend. You can wait for the result, |
  131. | | retrieve it later, or ignore it. |
  132. +-----------------+----------------------------------------------------+
  133. | Result Stores | Database, `MongoDB`_, `Redis`_, `Memcached`_, |
  134. | | `Cassandra`, or `AMQP`_ (message notification). |
  135. +-----------------+----------------------------------------------------+
  136. | Webhooks | Your tasks can also be HTTP callbacks, enabling |
  137. | | cross-language communication. |
  138. +-----------------+----------------------------------------------------+
  139. | Rate limiting | Supports rate limiting by using the token bucket |
  140. | | algorithm, which accounts for bursts of traffic. |
  141. | | Rate limits can be set for each task type, or |
  142. | | globally for all. |
  143. +-----------------+----------------------------------------------------+
  144. | Routing | Using AMQP's flexible routing model you can route |
  145. | | tasks to different workers, or select different |
  146. | | message topologies, by configuration or even at |
  147. | | runtime. |
  148. +-----------------+----------------------------------------------------+
  149. | Remote-control | Worker nodes can be controlled from remote by |
  150. | | using broadcast messaging. A range of built-in |
  151. | | commands exist in addition to the ability to |
  152. | | easily define your own. (AMQP/Redis only) |
  153. +-----------------+----------------------------------------------------+
  154. | Monitoring | You can capture everything happening with the |
  155. | | workers in real-time by subscribing to events. |
  156. | | A real-time web monitor is in development. |
  157. +-----------------+----------------------------------------------------+
  158. | Serialization | Supports Pickle, JSON, YAML, or easily defined |
  159. | | custom schemes. One task invocation can have a |
  160. | | different scheme than another. |
  161. +-----------------+----------------------------------------------------+
  162. | Tracebacks | Errors and tracebacks are stored and can be |
  163. | | investigated after the fact. |
  164. +-----------------+----------------------------------------------------+
  165. | UUID | Every task has an UUID (Universally Unique |
  166. | | Identifier), which is the task id used to query |
  167. | | task status and return value. |
  168. +-----------------+----------------------------------------------------+
  169. | Retries | Tasks can be retried if they fail, with |
  170. | | configurable maximum number of retries, and delays |
  171. | | between each retry. |
  172. +-----------------+----------------------------------------------------+
  173. | Task Sets | A Task set is a task consisting of several |
  174. | | sub-tasks. You can find out how many, or if all |
  175. | | of the sub-tasks has been executed, and even |
  176. | | retrieve the results in order. Progress bars, |
  177. | | anyone? |
  178. +-----------------+----------------------------------------------------+
  179. | Made for Web | You can query status and results via URLs, |
  180. | | enabling the ability to poll task status using |
  181. | | Ajax. |
  182. +-----------------+----------------------------------------------------+
  183. | Error Emails | Can be configured to send emails to the |
  184. | | administrators when tasks fails. |
  185. +-----------------+----------------------------------------------------+
  186. | Message signing | Supports message signing. Messages are signed |
  187. | | using public-key cryptography. |
  188. +-----------------+----------------------------------------------------+
  189. .. _`clustering`: http://www.rabbitmq.com/clustering.html
  190. .. _`HA`: http://www.rabbitmq.com/pacemaker.html
  191. .. _`AMQP`: http://www.amqp.org/
  192. .. _`Stomp`: http://stomp.codehaus.org/
  193. .. _`Tokyo Tyrant`: http://tokyocabinet.sourceforge.net/
  194. .. _celery-documentation:
  195. Documentation
  196. =============
  197. The `latest documentation`_ with user guides, tutorials and API reference
  198. is hosted at Read The Docs.
  199. .. _`latest documentation`: http://docs.celeryproject.org/en/latest/