introduction.txt 9.6 KB

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