configuration.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. BROKER_HOST = "localhost"
  19. BROKER_PORT = 5672
  20. BROKER_VHOST = "/"
  21. BROKER_USER = "guest"
  22. BROKER_PASSWORD = "guest"
  23. ## If you're doing mostly I/O you can have more processes,
  24. ## but if mostly spending CPU, try to keep it close to the
  25. ## number of CPUs on your machine. If not set, the number of CPUs/cores
  26. ## available will be used.
  27. # CELERYD_CONCURRENCY = 8
  28. # CELERYD_LOG_FILE = "celeryd.log"
  29. # CELERYD_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/cores available.
  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. * pyredis
  47. Use `Redis`_ to store the results.
  48. * tyrant
  49. Use `Tokyo Tyrant`_ to store the results.
  50. * amqp
  51. Send results back as AMQP messages
  52. (**WARNING** While very fast, you must make sure you only
  53. try to receive the result once).
  54. .. _`memcached`: http://memcached.org
  55. .. _`MongoDB`: http://mongodb.org
  56. .. _`Redis`: http://code.google.com/p/redis/
  57. .. _`Tokyo Tyrant`: http://1978th.net/tokyotyrant/
  58. Database backend settings
  59. =========================
  60. Please see the Django ORM database settings documentation:
  61. http://docs.djangoproject.com/en/dev/ref/settings/#database-engine
  62. If you use this backend make sure to initialize the database tables
  63. after configuration. When using celery with a Django project this
  64. means executing::
  65. $ python manage.py syncdb
  66. When using celery in a regular Python environment you have to execute::
  67. $ celeryinit
  68. Example configuration
  69. ---------------------
  70. .. code-block:: python
  71. CELERY_BACKEND = "database"
  72. DATABASE_ENGINE = "mysql"
  73. DATABASE_USER = "myusername"
  74. DATABASE_PASSWORD = "mypassword"
  75. DATABASE_NAME = "mydatabase"
  76. DATABASE_HOST = "localhost"
  77. AMQP backend settings
  78. =====================
  79. The AMQP backend does not have any settings yet.
  80. Example configuration
  81. ---------------------
  82. CELERY_BACKEND = "amqp"
  83. Cache backend settings
  84. ======================
  85. Please see the documentation for the Django cache framework settings:
  86. http://docs.djangoproject.com/en/dev/topics/cache/#memcached
  87. To use a custom cache backend for Celery, while using another for Django,
  88. you should use the ``CELERY_CACHE_BACKEND`` setting instead of the regular
  89. django ``CACHE_BACKEND`` setting.
  90. Example configuration
  91. ---------------------
  92. Using a single memcached server:
  93. .. code-block:: python
  94. CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
  95. Using multiple memcached servers:
  96. .. code-block:: python
  97. CELERY_BACKEND = "cache"
  98. CACHE_BACKEND = 'memcached://172.19.26.240:11211;172.19.26.242:11211/'
  99. Tokyo Tyrant backend settings
  100. =============================
  101. **NOTE** The Tokyo Tyrant backend requires the :mod:`pytyrant` library:
  102. http://pypi.python.org/pypi/pytyrant/
  103. This backend requires the following configuration directives to be set:
  104. * TT_HOST
  105. Hostname of the Tokyo Tyrant server.
  106. * TT_PORT
  107. The port the Tokyo Tyrant server is listening to.
  108. Example configuration
  109. ---------------------
  110. .. code-block:: python
  111. CELERY_BACKEND = "tyrant"
  112. TT_HOST = "localhost"
  113. TT_PORT = 1978
  114. Redis backend settings
  115. ======================
  116. **NOTE** The Redis backend requires the :mod:`redis` library:
  117. http://pypi.python.org/pypi/redis/0.5.5
  118. To install the redis package use ``pip`` or ``easy_install``::
  119. $ pip install redis
  120. This backend requires the following configuration directives to be set:
  121. * REDIS_HOST
  122. Hostname of the Redis database server. e.g. ``"localhost"``.
  123. * REDIS_PORT
  124. Port to the Redis database server. e.g. ``6379``.
  125. Also, the following optional configuration directives are available:
  126. * REDIS_DB
  127. Name of the database to use. Default is ``celery_results``.
  128. * REDIS_TIMEOUT
  129. Timeout in seconds before we give up establishing a connection
  130. to the Redis server.
  131. * REDIS_CONNECT_RETRY
  132. Retry connecting if an connection could not be established. Default is
  133. false.
  134. Example configuration
  135. ---------------------
  136. .. code-block:: python
  137. CELERY_BACKEND = "pyredis"
  138. REDIS_HOST = "localhost"
  139. REDIS_PORT = 6739
  140. REDIS_DATABASE = "celery_results"
  141. REDIS_CONNECT_RETRY=True
  142. MongoDB backend settings
  143. ========================
  144. **NOTE** The MongoDB backend requires the :mod:`pymongo` library:
  145. http://github.com/mongodb/mongo-python-driver/tree/master
  146. * CELERY_MONGODB_BACKEND_SETTINGS
  147. This is a dict supporting the following keys:
  148. * host
  149. Hostname of the MongoDB server. Defaults to "localhost".
  150. * port
  151. The port the MongoDB server is listening to. Defaults to 27017.
  152. * user
  153. Username to authenticate to the MongoDB server as (optional).
  154. * password
  155. Password to authenticate to the MongoDB server (optional).
  156. * database
  157. The database name to connect to. Defaults to "celery".
  158. * taskmeta_collection
  159. The collection name to store task metadata.
  160. Defaults to "celery_taskmeta".
  161. Example configuration
  162. ---------------------
  163. .. code-block:: python
  164. CELERY_BACKEND = "mongodb"
  165. CELERY_MONGODB_BACKEND_SETTINGS = {
  166. "host": "192.168.1.100",
  167. "port": 30000,
  168. "database": "mydb",
  169. "taskmeta_collection": "my_taskmeta_collection",
  170. }
  171. Messaging settings
  172. ==================
  173. Routing
  174. -------
  175. * CELERY_QUEUES
  176. The mapping of queues the worker consumes from. This is a dictionary
  177. of queue name/options. See :doc:`userguide/routing` for more information.
  178. The default is a queue/exchange/binding key of ``"celery"``, with
  179. exchange type ``direct``.
  180. You don't have to care about this unless you want custom routing facilities.
  181. * CELERY_DEFAULT_QUEUE
  182. The queue used by default, if no custom queue is specified.
  183. This queue must be listed in ``CELERY_QUEUES``.
  184. The default is: ``celery``.
  185. * CELERY_DEFAULT_EXCHANGE
  186. Name of the default exchange to use when no custom exchange
  187. is specified.
  188. The default is: ``celery``.
  189. * CELERY_DEFAULT_EXCHANGE_TYPE
  190. Default exchange type used when no custom exchange is specified.
  191. The default is: ``direct``.
  192. * CELERY_DEFAULT_ROUTING_KEY
  193. The default routing key used when sending tasks.
  194. The default is: ``celery``.
  195. Connection
  196. ----------
  197. * CELERY_BROKER_CONNECTION_TIMEOUT
  198. The timeout in seconds before we give up establishing a connection
  199. to the AMQP server. Default is 4 seconds.
  200. * CELERY_BROKER_CONNECTION_RETRY
  201. Automatically try to re-establish the connection to the AMQP broker if
  202. it's lost.
  203. The time between retries is increased for each retry, and is
  204. not exhausted before ``CELERY_BROKER_CONNECTION_MAX_RETRIES`` is exceeded.
  205. This behaviour is on by default.
  206. * CELERY_BROKER_CONNECTION_MAX_RETRIES
  207. Maximum number of retries before we give up re-establishing a connection
  208. to the AMQP broker.
  209. If this is set to ``0`` or ``None``, we will retry forever.
  210. Default is 100 retries.
  211. Task execution settings
  212. =======================
  213. * CELERY_ALWAYS_EAGER
  214. If this is ``True``, all tasks will be executed locally by blocking
  215. until it is finished. ``apply_async`` and ``Task.delay`` will return
  216. a :class:`celery.result.EagerResult` which emulates the behaviour of
  217. :class:`celery.result.AsyncResult`, except the result has already
  218. been evaluated.
  219. Tasks will never be sent to the queue, but executed locally
  220. instead.
  221. * CELERY_IGNORE_RESULT
  222. Wheter to store the task return values or not (tombstones).
  223. If you still want to store errors, just not successful return values,
  224. you can set ``CELERY_STORE_ERRORS_EVEN_IF_IGNORED``.
  225. * CELERY_TASK_RESULT_EXPIRES
  226. Time (in seconds, or a :class:`datetime.timedelta` object) for when after
  227. stored task tombstones are deleted.
  228. **NOTE**: For the moment this only works for the database and MongoDB
  229. backends., except the result has already
  230. been evaluated.
  231. * CELERY_TASK_SERIALIZER
  232. A string identifying the default serialization
  233. method to use. Can be ``pickle`` (default),
  234. ``json``, ``yaml``, or any custom serialization methods that have
  235. been registered with :mod:`carrot.serialization.registry`.
  236. Default is ``pickle``.
  237. Worker: celeryd
  238. ===============
  239. * CELERY_IMPORTS
  240. A sequence of modules to import when the celery daemon starts. This is
  241. useful to add tasks if you are not using django or cannot use task
  242. autodiscovery.
  243. * CELERY_SEND_EVENTS
  244. Send events so the worker can be monitored by tools like ``celerymon``.
  245. * CELERY_SEND_TASK_ERROR_EMAILS
  246. If set to ``True``, errors in tasks will be sent to admins by e-mail.
  247. If unset, it will send the e-mails if ``settings.DEBUG`` is False.
  248. * CELERY_STORE_ERRORS_EVEN_IF_IGNORED
  249. If set, the worker stores all task errors in the result store even if
  250. ``Task.ignore_result`` is on.
  251. Logging
  252. -------
  253. * CELERYD_LOG_FILE
  254. The default filename the worker daemon logs messages to, can be
  255. overridden using the `--logfile`` option to ``celeryd``.
  256. The default is ``None`` (``stderr``)
  257. Can also be set via the ``--logfile`` argument.
  258. * CELERYD_LOG_LEVEL
  259. Worker log level, can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  260. ``ERROR``, ``CRITICAL``.
  261. Can also be set via the ``--loglevel`` argument.
  262. See the :mod:`logging` module for more information.
  263. * CELERYD_LOG_FORMAT
  264. The format to use for log messages. Can be overridden using
  265. the ``--loglevel`` option to ``celeryd``.
  266. Default is ``[%(asctime)s: %(levelname)s/%(processName)s] %(message)s``
  267. See the Python :mod:`logging` module for more information about log
  268. formats.
  269. Periodic Task Server: celerybeat
  270. ================================
  271. * CELERYBEAT_SCHEDULE_FILENAME
  272. Name of the file celerybeat stores the current schedule in.
  273. Can be a relative or absolute path, but be aware that the suffix ``.db``
  274. will be appended to the filename.
  275. Can also be set via the ``--schedule`` argument.
  276. * CELERYBEAT_MAX_LOOP_INTERVAL
  277. The maximum number of seconds celerybeat can sleep between checking
  278. the schedule. Default is 300 seconds (5 minutes).
  279. * CELERYBEAT_LOG_FILE
  280. The default filename to log messages to, can be
  281. overridden using the `--logfile`` option.
  282. The default is ``None`` (``stderr``).
  283. Can also be set via the ``--logfile`` argument.
  284. * CELERYBEAT_LOG_LEVEL
  285. Logging level. Can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  286. ``ERROR``, or ``CRITICAL``.
  287. Can also be set via the ``--loglevel`` argument.
  288. See the :mod:`logging` module for more information.
  289. Monitor Server: celerymon
  290. =========================
  291. * CELERYMON_LOG_FILE
  292. The default filename to log messages to, can be
  293. overridden using the `--logfile`` option.
  294. The default is ``None`` (``stderr``)
  295. Can also be set via the ``--logfile`` argument.
  296. * CELERYMON_LOG_LEVEL
  297. Logging level. Can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  298. ``ERROR``, or ``CRITICAL``.
  299. See the :mod:`logging` module for more information.