configuration.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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_RESULT_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_RESULT_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_RESULT_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_RESULT_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_RESULT_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_RESULT_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_PASSWORD
  137. Password used to connect to the database.
  138. Example configuration
  139. ---------------------
  140. .. code-block:: python
  141. CELERY_RESULT_BACKEND = "redis"
  142. REDIS_HOST = "localhost"
  143. REDIS_PORT = 6379
  144. REDIS_DATABASE = "celery_results"
  145. REDIS_CONNECT_RETRY=True
  146. MongoDB backend settings
  147. ========================
  148. **NOTE** The MongoDB backend requires the :mod:`pymongo` library:
  149. http://github.com/mongodb/mongo-python-driver/tree/master
  150. * CELERY_MONGODB_BACKEND_SETTINGS
  151. This is a dict supporting the following keys:
  152. * host
  153. Hostname of the MongoDB server. Defaults to "localhost".
  154. * port
  155. The port the MongoDB server is listening to. Defaults to 27017.
  156. * user
  157. User name to authenticate to the MongoDB server as (optional).
  158. * password
  159. Password to authenticate to the MongoDB server (optional).
  160. * database
  161. The database name to connect to. Defaults to "celery".
  162. * taskmeta_collection
  163. The collection name to store task meta data.
  164. Defaults to "celery_taskmeta".
  165. Example configuration
  166. ---------------------
  167. .. code-block:: python
  168. CELERY_RESULT_BACKEND = "mongodb"
  169. CELERY_MONGODB_BACKEND_SETTINGS = {
  170. "host": "192.168.1.100",
  171. "port": 30000,
  172. "database": "mydb",
  173. "taskmeta_collection": "my_taskmeta_collection",
  174. }
  175. Messaging settings
  176. ==================
  177. Routing
  178. -------
  179. * CELERY_QUEUES
  180. The mapping of queues the worker consumes from. This is a dictionary
  181. of queue name/options. See :doc:`userguide/routing` for more information.
  182. The default is a queue/exchange/binding key of ``"celery"``, with
  183. exchange type ``direct``.
  184. You don't have to care about this unless you want custom routing facilities.
  185. * CELERY_DEFAULT_QUEUE
  186. The queue used by default, if no custom queue is specified.
  187. This queue must be listed in ``CELERY_QUEUES``.
  188. The default is: ``celery``.
  189. * CELERY_DEFAULT_EXCHANGE
  190. Name of the default exchange to use when no custom exchange
  191. is specified.
  192. The default is: ``celery``.
  193. * CELERY_DEFAULT_EXCHANGE_TYPE
  194. Default exchange type used when no custom exchange is specified.
  195. The default is: ``direct``.
  196. * CELERY_DEFAULT_ROUTING_KEY
  197. The default routing key used when sending tasks.
  198. The default is: ``celery``.
  199. Connection
  200. ----------
  201. * CELERY_BROKER_CONNECTION_TIMEOUT
  202. The timeout in seconds before we give up establishing a connection
  203. to the AMQP server. Default is 4 seconds.
  204. * CELERY_BROKER_CONNECTION_RETRY
  205. Automatically try to re-establish the connection to the AMQP broker if
  206. it's lost.
  207. The time between retries is increased for each retry, and is
  208. not exhausted before ``CELERY_BROKER_CONNECTION_MAX_RETRIES`` is exceeded.
  209. This behavior is on by default.
  210. * CELERY_BROKER_CONNECTION_MAX_RETRIES
  211. Maximum number of retries before we give up re-establishing a connection
  212. to the AMQP broker.
  213. If this is set to ``0`` or ``None``, we will retry forever.
  214. Default is 100 retries.
  215. Task execution settings
  216. =======================
  217. * CELERY_ALWAYS_EAGER
  218. If this is ``True``, all tasks will be executed locally by blocking
  219. until it is finished. ``apply_async`` and ``Task.delay`` will return
  220. a :class:`celery.result.EagerResult` which emulates the behavior of
  221. :class:`celery.result.AsyncResult`, except the result has already
  222. been evaluated.
  223. Tasks will never be sent to the queue, but executed locally
  224. instead.
  225. * CELERY_IGNORE_RESULT
  226. Whether to store the task return values or not (tombstones).
  227. If you still want to store errors, just not successful return values,
  228. you can set ``CELERY_STORE_ERRORS_EVEN_IF_IGNORED``.
  229. * CELERY_TASK_RESULT_EXPIRES
  230. Time (in seconds, or a :class:`datetime.timedelta` object) for when after
  231. stored task tombstones are deleted.
  232. **NOTE**: For the moment this only works with the database, cache and MongoDB
  233. backends.
  234. * CELERY_TASK_SERIALIZER
  235. A string identifying the default serialization
  236. method to use. Can be ``pickle`` (default),
  237. ``json``, ``yaml``, or any custom serialization methods that have
  238. been registered with :mod:`carrot.serialization.registry`.
  239. Default is ``pickle``.
  240. * CELERY_DEFAULT_RATE_LIMIT
  241. The global default rate limit for tasks.
  242. This value is used for tasks that does not have a custom rate limit
  243. The default is no rate limit.
  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.