introduction.txt 9.4 KB

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