introduction.txt 9.2 KB

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