introduction.txt 8.8 KB

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