configuration.rst 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. ============================
  2. Configuration and defaults
  3. ============================
  4. This document describes the configuration options available.
  5. If you're using celery in a Django project these settings should be defined
  6. in your projects ``settings.py`` file.
  7. In a regular Python environment using the default loader you must create
  8. the ``celeryconfig.py`` module and make sure it is available on the
  9. Python path.
  10. Example configuration file
  11. ==========================
  12. This is an example configuration file to get you started,
  13. it should contain all you need to run a basic celery set-up.
  14. .. code-block:: python
  15. CELERY_BACKEND = "database"
  16. DATABASE_ENGINE = "sqlite3"
  17. DATABASE_NAME = "mydatabase.db"
  18. AMQP_SERVER = "localhost"
  19. AMQP_PORT = 5672
  20. AMQP_VHOST = "/"
  21. AMQP_USER = "guest"
  22. AMQP_PASSWORD = "guest"
  23. ## If you're doing mostly I/O you can have higher concurrency,
  24. ## if mostly spending time in the CPU, try to keep it close to the
  25. ## number of CPUs on your machine.
  26. # CELERYD_CONCURRENCY = 8
  27. CELERYD_LOG_FILE = "celeryd.log"
  28. CELERYD_PID_FILE = "celeryd.pid"
  29. CELERYD_DAEMON_LOG_LEVEL = "INFO"
  30. Concurrency settings
  31. ====================
  32. * CELERYD_CONCURRENCY
  33. The number of concurrent worker processes, executing tasks simultaneously.
  34. Defaults to the number of CPUs in the system.
  35. Task result backend settings
  36. ============================
  37. * CELERY_BACKEND
  38. The backend used to store task results (tombstones).
  39. Can be one of the following:
  40. * database (default)
  41. Use a relational database supported by the Django ORM.
  42. * cache
  43. Use memcached to store the results.
  44. * mongodb
  45. Use MongoDB to store the results.
  46. * tyrant
  47. Use Tokyo Tyrant to store the results.
  48. * amqp
  49. Send results back as AMQP messages
  50. (**WARNING** While very fast, you must make sure you only
  51. try to receive the result once).
  52. * CELERY_PERIODIC_STATUS_BACKEND
  53. The backend used to store the status of periodic tasks.
  54. Can be one of the following:
  55. * database (default)
  56. Use a relational database supported by the Django ORM.
  57. * mongodb
  58. Use MongoDB.
  59. Database backend settings
  60. =========================
  61. This applies to both the result store backend and the periodic status
  62. backend.
  63. Please see the Django ORM database settings documentation:
  64. http://docs.djangoproject.com/en/dev/ref/settings/#database-engine
  65. If you use this backend make sure to initialize the database tables
  66. after configuration. When using celery with a Django project this
  67. means executing::
  68. $ python manage.py syncdb
  69. When using celery in a regular Python environment you have to execute::
  70. $ celeryinit
  71. Example configuration
  72. ---------------------
  73. .. code-block:: python
  74. DATABASE_ENGINE="mysql"
  75. DATABASE_USER="myusername"
  76. DATABASE_PASSWORD="mypassword"
  77. DATABASE_NAME="mydatabase"
  78. DATABASE_HOST="localhost"
  79. Cache backend settings
  80. ======================
  81. Please see the documentation for the Django cache framework settings:
  82. http://docs.djangoproject.com/en/dev/topics/cache/#memcached
  83. To use a custom cache backend for Celery, while using another for Django,
  84. you should use the ``CELERY_CACHE_BACKEND`` setting instead of the regular
  85. django ``CACHE_BACKEND`` setting.
  86. Example configuration
  87. ---------------------
  88. Using a single memcached server:
  89. .. code-block:: python
  90. CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
  91. Using multiple memcached servers:
  92. .. code-block:: python
  93. CACHE_BACKEND = 'memcached://172.19.26.240:11211;172.19.26.242:11211/'
  94. Tokyo Tyrant backend settings
  95. =============================
  96. **NOTE** The Tokyo Tyrant backend requires the :mod:`pytyrant` library:
  97. http://pypi.python.org/pypi/pytyrant/
  98. This backend requires the following configuration variables to be set:
  99. * TT_HOST
  100. Hostname of the Tokyo Tyrant server.
  101. * TT_PORT
  102. The port the Tokyo Tyrant server is listening to.
  103. Example configuration
  104. ---------------------
  105. .. code-block:: python
  106. TT_HOST = "localhost"
  107. TT_PORT = 1978
  108. MongoDB backend settings
  109. ========================
  110. **NOTE** The MongoDB backend requires the :mod:`pymongo` library:
  111. http://github.com/mongodb/mongo-python-driver/tree/master
  112. * CELERY_MONGODB_BACKEND_SETTINGS
  113. This is a dict supporting the following keys:
  114. * host
  115. Hostname of the MongoDB server. Defaults to "localhost".
  116. * port
  117. The port the MongoDB server is listening to. Defaults to 27017.
  118. * user
  119. Username to authenticate to the MongoDB server as (optional).
  120. * password
  121. Password to authenticate to the MongoDB server (optional).
  122. * database
  123. The database name to connect to. Defaults to "celery".
  124. * taskmeta_collection
  125. The collection name to store task metadata.
  126. Defaults to "celery_taskmeta".
  127. * periodictaskmeta_collection
  128. The collection name to store periodic task metadata.
  129. Defaults to "celery_periodictaskmeta".
  130. Example configuration
  131. ---------------------
  132. .. code-block:: python
  133. CELERY_MONGODB_BACKEND_SETTINGS = {
  134. "host": "192.168.1.100",
  135. "port": 30000,
  136. "database": "mydb",
  137. "taskmeta_collection": "my_taskmeta_collection",
  138. }
  139. Broker settings
  140. ===============
  141. * CELERY_AMQP_EXCHANGE
  142. Name of the AMQP exchange.
  143. * CELERY_AMQP_EXCHANGE_TYPE
  144. The type of exchange. If the exchange type is ``direct``, all messages
  145. receives all tasks. However, if the exchange type is ``topic``, you can
  146. route e.g. some tasks to one server, and others to the rest.
  147. See `Exchange types and the effect of bindings`_.
  148. .. _`Exchange types and the effect of bindings`:
  149. http://bit.ly/wpamqpexchanges
  150. * CELERY_AMQP_PUBLISHER_ROUTING_KEY
  151. The default AMQP routing key used when publishing tasks.
  152. * CELERY_AMQP_CONSUMER_ROUTING_KEY
  153. The AMQP routing key used when consuming tasks.
  154. * CELERY_AMQP_CONSUMER_QUEUE
  155. The name of the AMQP queue.
  156. * CELERY_AMQP_CONSUMER_QUEUES
  157. Dictionary defining multiple AMQP queues.
  158. * CELERY_AMQP_CONNECTION_TIMEOUT
  159. The timeout in seconds before we give up establishing a connection
  160. to the AMQP server. Default is 4 seconds.
  161. * CELERY_AMQP_CONNECTION_RETRY
  162. Automatically try to re-establish the connection to the AMQP broker if
  163. it's lost.
  164. The time between retries is increased for each retry, and is
  165. not exhausted before ``CELERY_AMQP_CONNECTION_MAX_RETRIES`` is exceeded.
  166. This behaviour is on by default.
  167. * CELERY_AMQP_CONNECTION_MAX_RETRIES
  168. Maximum number of retries before we give up re-establishing a connection
  169. to the AMQP broker.
  170. If this is set to ``0`` or ``None``, we will retry forever.
  171. Default is 100 retries.
  172. Task execution settings
  173. =======================
  174. * SEND_CELERY_TASK_ERROR_EMAILS
  175. If set to ``True``, errors in tasks will be sent to admins by e-mail.
  176. If unset, it will send the e-mails if ``settings.DEBUG`` is False.
  177. * CELERY_ALWAYS_EAGER
  178. If this is ``True``, all tasks will be executed locally by blocking
  179. until it is finished. ``apply_async`` and ``delay_task`` will return
  180. a :class:`celery.result.EagerResult` which emulates the behaviour of
  181. an :class:`celery.result.AsyncResult`.
  182. Tasks will never be sent to the queue, but executed locally
  183. instead.
  184. * CELERY_TASK_RESULT_EXPIRES
  185. Time (in seconds, or a :class:`datetime.timedelta` object) for when after
  186. stored task tombstones are deleted.
  187. **NOTE**: For the moment this only works for the database and MongoDB
  188. backends.
  189. * CELERY_TASK_SERIALIZER
  190. A string identifying the default serialization
  191. method to use. Can be ``pickle`` (default),
  192. ``json``, ``yaml``, or any custom serialization methods that have
  193. been registered with :mod:`carrot.serialization.registry`.
  194. Default is ``pickle``.
  195. Logging settings
  196. ================
  197. * CELERYD_LOG_FILE
  198. The default filename the worker daemon logs messages to, can be
  199. overridden using the `--logfile`` option to ``celeryd``.
  200. The default is to log using ``stderr`` if running in the foreground,
  201. when running in the background, detached as a daemon, the default
  202. logfile is ``celeryd.log``.
  203. * CELERYD_DAEMON_LOG_LEVEL
  204. Worker log level, can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  205. ``ERROR``, ``CRITICAL``, or ``FATAL``.
  206. See the :mod:`logging` module for more information.
  207. * CELERYD_DAEMON_LOG_FORMAT
  208. The format to use for log messages. Can be overridden using
  209. the ``--loglevel`` option to ``celeryd``.
  210. Default is ``[%(asctime)s: %(levelname)s/%(processName)s] %(message)s``
  211. See the Python :mod:`logging` module for more information about log
  212. formats.
  213. Process settings
  214. ================
  215. * CELERYD_PID_FILE
  216. Full path to the daemon pid file. Default is ``celeryd.pid``.
  217. Can be overridden using the ``--pidfile`` option to ``celeryd``.