introduction.txt 12 KB

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