introduction.txt 10 KB

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