configuration.rst 12 KB

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