configuration.rst 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  1. .. _configuration:
  2. ============================
  3. Configuration and defaults
  4. ============================
  5. This document describes the configuration options available.
  6. If you're using the default loader, you must create the :file:`celeryconfig.py`
  7. module and make sure it is available on the Python path.
  8. .. contents::
  9. :local:
  10. :depth: 2
  11. .. _conf-example:
  12. Example configuration file
  13. ==========================
  14. This is an example configuration file to get you started.
  15. It should contain all you need to run a basic Celery set-up.
  16. .. code-block:: python
  17. ## Broker settings.
  18. broker_url = 'amqp://guest:guest@localhost:5672//'
  19. # List of modules to import when celery starts.
  20. imports = ('myapp.tasks',)
  21. ## Using the database to store task state and results.
  22. result_backend = 'db+sqlite:///results.db'
  23. task_annotations = {'tasks.add': {'rate_limit': '10/s'}}
  24. Configuration Directives
  25. ========================
  26. .. _conf-datetime:
  27. General settings
  28. ----------------
  29. .. setting:: accept_content
  30. accept_content
  31. ~~~~~~~~~~~~~~
  32. A whitelist of content-types/serializers to allow.
  33. If a message is received that is not in this list then
  34. the message will be discarded with an error.
  35. By default any content type is enabled (including pickle and yaml)
  36. so make sure untrusted parties do not have access to your broker.
  37. See :ref:`guide-security` for more.
  38. Example::
  39. # using serializer name
  40. accept_content = ['json']
  41. # or the actual content-type (MIME)
  42. accept_content = ['application/json']
  43. Time and date settings
  44. ----------------------
  45. .. setting:: enable_utc
  46. enable_utc
  47. ~~~~~~~~~~
  48. .. versionadded:: 2.5
  49. If enabled dates and times in messages will be converted to use
  50. the UTC timezone.
  51. Note that workers running Celery versions below 2.5 will assume a local
  52. timezone for all messages, so only enable if all workers have been
  53. upgraded.
  54. Enabled by default since version 3.0.
  55. .. setting:: timezone
  56. timezone
  57. ~~~~~~~~
  58. Configure Celery to use a custom time zone.
  59. The timezone value can be any time zone supported by the `pytz`_
  60. library.
  61. If not set the UTC timezone is used. For backwards compatibility
  62. there is also a :setting:`enable_utc` setting, and this is set
  63. to false the system local timezone is used instead.
  64. .. _`pytz`: http://pypi.python.org/pypi/pytz/
  65. .. _conf-tasks:
  66. Task settings
  67. -------------
  68. .. setting:: task_annotations
  69. task_annotations
  70. ~~~~~~~~~~~~~~~~
  71. This setting can be used to rewrite any task attribute from the
  72. configuration. The setting can be a dict, or a list of annotation
  73. objects that filter for tasks and return a map of attributes
  74. to change.
  75. This will change the ``rate_limit`` attribute for the ``tasks.add``
  76. task:
  77. .. code-block:: python
  78. task_annotations = {'tasks.add': {'rate_limit': '10/s'}}
  79. or change the same for all tasks:
  80. .. code-block:: python
  81. task_annotations = {'*': {'rate_limit': '10/s'}}
  82. You can change methods too, for example the ``on_failure`` handler:
  83. .. code-block:: python
  84. def my_on_failure(self, exc, task_id, args, kwargs, einfo):
  85. print('Oh no! Task failed: {0!r}'.format(exc))
  86. task_annotations = {'*': {'on_failure': my_on_failure}}
  87. If you need more flexibility then you can use objects
  88. instead of a dict to choose which tasks to annotate:
  89. .. code-block:: python
  90. class MyAnnotate(object):
  91. def annotate(self, task):
  92. if task.name.startswith('tasks.'):
  93. return {'rate_limit': '10/s'}
  94. task_annotations = (MyAnnotate(), {…})
  95. .. setting:: task_compression
  96. task_compression
  97. ~~~~~~~~~~~~~~~~
  98. Default compression used for task messages.
  99. Can be ``gzip``, ``bzip2`` (if available), or any custom
  100. compression schemes registered in the Kombu compression registry.
  101. The default is to send uncompressed messages.
  102. .. setting:: task_protocol
  103. task_protocol
  104. ~~~~~~~~~~~~~
  105. Default task message protocol version.
  106. Supports protocols: 1 and 2 (default is 1 for backwards compatibility).
  107. .. setting:: task_serializer
  108. task_serializer
  109. ~~~~~~~~~~~~~~~
  110. A string identifying the default serialization method to use. Can be
  111. `pickle` (default), `json`, `yaml`, `msgpack` or any custom serialization
  112. methods that have been registered with :mod:`kombu.serialization.registry`.
  113. .. seealso::
  114. :ref:`calling-serializers`.
  115. .. setting:: task_publish_retry
  116. task_publish_retry
  117. ~~~~~~~~~~~~~~~~~~
  118. .. versionadded:: 2.2
  119. Decides if publishing task messages will be retried in the case
  120. of connection loss or other connection errors.
  121. See also :setting:`task_publish_retry_policy`.
  122. Enabled by default.
  123. .. setting:: task_publish_retry_policy
  124. task_publish_retry_policy
  125. ~~~~~~~~~~~~~~~~~~~~~~~~~
  126. .. versionadded:: 2.2
  127. Defines the default policy when retrying publishing a task message in
  128. the case of connection loss or other connection errors.
  129. See :ref:`calling-retry` for more information.
  130. .. _conf-task-execution:
  131. Task execution settings
  132. -----------------------
  133. .. setting:: task_always_eager
  134. task_always_eager
  135. ~~~~~~~~~~~~~~~~~
  136. If this is :const:`True`, all tasks will be executed locally by blocking until
  137. the task returns. ``apply_async()`` and ``Task.delay()`` will return
  138. an :class:`~celery.result.EagerResult` instance, which emulates the API
  139. and behavior of :class:`~celery.result.AsyncResult`, except the result
  140. is already evaluated.
  141. That is, tasks will be executed locally instead of being sent to
  142. the queue.
  143. .. setting:: task_eager_propagates_exceptions
  144. task_eager_propagates_exceptions
  145. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  146. If this is :const:`True`, eagerly executed tasks (applied by `task.apply()`,
  147. or when the :setting:`task_always_eager` setting is enabled), will
  148. propagate exceptions.
  149. It's the same as always running ``apply()`` with ``throw=True``.
  150. .. setting:: task_ignore_result
  151. task_ignore_result
  152. ~~~~~~~~~~~~~~~~~~
  153. Whether to store the task return values or not (tombstones).
  154. If you still want to store errors, just not successful return values,
  155. you can set :setting:`task_store_errors_even_if_ignored`.
  156. .. setting:: task_store_errors_even_if_ignored
  157. task_store_errors_even_if_ignored
  158. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  159. If set, the worker stores all task errors in the result store even if
  160. :attr:`Task.ignore_result <celery.task.base.Task.ignore_result>` is on.
  161. .. setting:: task_track_started
  162. task_track_started
  163. ~~~~~~~~~~~~~~~~~~
  164. If :const:`True` the task will report its status as "started" when the
  165. task is executed by a worker. The default value is :const:`False` as
  166. the normal behaviour is to not report that level of granularity. Tasks
  167. are either pending, finished, or waiting to be retried. Having a "started"
  168. state can be useful for when there are long running tasks and there is a
  169. need to report which task is currently running.
  170. .. setting:: task_time_limit
  171. task_time_limit
  172. ~~~~~~~~~~~~~~~
  173. Task hard time limit in seconds. The worker processing the task will
  174. be killed and replaced with a new one when this is exceeded.
  175. .. setting:: task_soft_time_limit
  176. task_soft_time_limit
  177. ~~~~~~~~~~~~~~~~~~~~
  178. Task soft time limit in seconds.
  179. The :exc:`~@SoftTimeLimitExceeded` exception will be
  180. raised when this is exceeded. The task can catch this to
  181. e.g. clean up before the hard time limit comes.
  182. Example:
  183. .. code-block:: python
  184. from celery.exceptions import SoftTimeLimitExceeded
  185. @app.task
  186. def mytask():
  187. try:
  188. return do_work()
  189. except SoftTimeLimitExceeded:
  190. cleanup_in_a_hurry()
  191. .. setting:: task_acks_late
  192. task_acks_late
  193. ~~~~~~~~~~~~~~
  194. Late ack means the task messages will be acknowledged **after** the task
  195. has been executed, not *just before*, which is the default behavior.
  196. .. seealso::
  197. FAQ: :ref:`faq-acks_late-vs-retry`.
  198. .. setting:: task_reject_on_worker_lost
  199. task_reject_on_worker_lost
  200. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  201. Even if :setting:`task_acks_late` is enabled, the worker will
  202. acknowledge tasks when the worker process executing them abrubtly
  203. exits or is signalled (e.g. :sig:`KILL`/:sig:`INT`, etc).
  204. Setting this to true allows the message to be requeued instead,
  205. so that the task will execute again by the same worker, or another
  206. worker.
  207. .. warning::
  208. Enabling this can cause message loops; make sure you know
  209. what you're doing.
  210. .. setting:: task_default_rate_limit
  211. task_default_rate_limit
  212. ~~~~~~~~~~~~~~~~~~~~~~~
  213. The global default rate limit for tasks.
  214. This value is used for tasks that does not have a custom rate limit
  215. The default is no rate limit.
  216. .. seealso::
  217. The setting:`worker_disable_rate_limits` setting can
  218. disable all rate limits.
  219. .. _conf-result-backend:
  220. Task result backend settings
  221. ----------------------------
  222. .. setting:: result_backend
  223. result_backend
  224. ~~~~~~~~~~~~~~
  225. The backend used to store task results (tombstones).
  226. Disabled by default.
  227. Can be one of the following:
  228. * rpc
  229. Send results back as AMQP messages
  230. See :ref:`conf-rpc-result-backend`.
  231. * database
  232. Use a relational database supported by `SQLAlchemy`_.
  233. See :ref:`conf-database-result-backend`.
  234. * redis
  235. Use `Redis`_ to store the results.
  236. See :ref:`conf-redis-result-backend`.
  237. * cache
  238. Use `memcached`_ to store the results.
  239. See :ref:`conf-cache-result-backend`.
  240. * mongodb
  241. Use `MongoDB`_ to store the results.
  242. See :ref:`conf-mongodb-result-backend`.
  243. * cassandra
  244. Use `Cassandra`_ to store the results.
  245. See :ref:`conf-cassandra-result-backend`.
  246. * ironcache
  247. Use `IronCache`_ to store the results.
  248. See :ref:`conf-ironcache-result-backend`.
  249. * couchbase
  250. Use `Couchbase`_ to store the results.
  251. See :ref:`conf-couchbase-result-backend`.
  252. * couchdb
  253. Use `CouchDB`_ to store the results.
  254. See :ref:`conf-couchdb-result-backend`.
  255. * amqp
  256. Older AMQP backend (badly) emulating a database-based backend.
  257. See :ref:`conf-amqp-result-backend`.
  258. .. warning:
  259. While the AMQP result backend is very efficient, you must make sure
  260. you only receive the same result once. See :doc:`userguide/calling`).
  261. .. _`SQLAlchemy`: http://sqlalchemy.org
  262. .. _`memcached`: http://memcached.org
  263. .. _`MongoDB`: http://mongodb.org
  264. .. _`Redis`: http://redis.io
  265. .. _`Cassandra`: http://cassandra.apache.org/
  266. .. _`IronCache`: http://www.iron.io/cache
  267. .. _`CouchDB`: http://www.couchdb.com/
  268. .. _`Couchbase`: http://www.couchbase.com/
  269. .. setting:: result_serializer
  270. result_serializer
  271. ~~~~~~~~~~~~~~~~~
  272. Result serialization format. Default is ``pickle``. See
  273. :ref:`calling-serializers` for information about supported
  274. serialization formats.
  275. .. setting:: result_compression
  276. result_compression
  277. ~~~~~~~~~~~~~~~~~~
  278. Optional compression method used for task results.
  279. Supports the same options as the :setting:`task_serializer` setting.
  280. Default is no compression.
  281. .. setting:: result_expires
  282. result_expires
  283. ~~~~~~~~~~~~~~
  284. Time (in seconds, or a :class:`~datetime.timedelta` object) for when after
  285. stored task tombstones will be deleted.
  286. A built-in periodic task will delete the results after this time
  287. (``celery.backend_cleanup``), assuming that ``celery beat`` is
  288. enabled. The task runs daily at 4am.
  289. A value of :const:`None` or 0 means results will never expire (depending
  290. on backend specifications).
  291. Default is to expire after 1 day.
  292. .. note::
  293. For the moment this only works with the amqp, database, cache, redis and MongoDB
  294. backends.
  295. When using the database or MongoDB backends, `celery beat` must be
  296. running for the results to be expired.
  297. .. setting:: result_cache_max
  298. result_cache_max
  299. ~~~~~~~~~~~~~~~~
  300. Result backends caches ready results used by the client.
  301. This is the total number of results to cache before older results are evicted.
  302. The default is 5000. 0 or None means no limit, and a value of :const:`-1`
  303. will disable the cache.
  304. .. _conf-database-result-backend:
  305. Database backend settings
  306. -------------------------
  307. Database URL Examples
  308. ~~~~~~~~~~~~~~~~~~~~~
  309. To use the database backend you have to configure the
  310. :setting:`result_backend` setting with a connection URL and the ``db+``
  311. prefix:
  312. .. code-block:: python
  313. result_backend = 'db+scheme://user:password@host:port/dbname'
  314. Examples::
  315. # sqlite (filename)
  316. result_backend = 'db+sqlite:///results.sqlite'
  317. # mysql
  318. result_backend = 'db+mysql://scott:tiger@localhost/foo'
  319. # postgresql
  320. result_backend = 'db+postgresql://scott:tiger@localhost/mydatabase'
  321. # oracle
  322. result_backend = 'db+oracle://scott:tiger@127.0.0.1:1521/sidname'
  323. .. code-block:: python
  324. Please see `Supported Databases`_ for a table of supported databases,
  325. and `Connection String`_ for more information about connection
  326. strings (which is the part of the URI that comes after the ``db+`` prefix).
  327. .. _`Supported Databases`:
  328. http://www.sqlalchemy.org/docs/core/engines.html#supported-databases
  329. .. _`Connection String`:
  330. http://www.sqlalchemy.org/docs/core/engines.html#database-urls
  331. .. setting:: sqlalchemy_dburi
  332. sqlalchemy_dburi
  333. ~~~~~~~~~~~~~~~~
  334. This setting is no longer used as it's now possible to specify
  335. the database URL directly in the :setting:`result_backend` setting.
  336. .. setting:: sqlalchemy_engine_options
  337. sqlalchemy_engine_options
  338. ~~~~~~~~~~~~~~~~~~~~~~~~~
  339. To specify additional SQLAlchemy database engine options you can use
  340. the :setting:`sqlalchmey_engine_options` setting::
  341. # echo enables verbose logging from SQLAlchemy.
  342. sqlalchemy_engine_options = {'echo': True}
  343. .. setting:: sqlalchemy_short_lived_sessions
  344. sqlalchemy_short_lived_sessions
  345. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  346. sqlalchemy_short_lived_sessions = True
  347. Short lived sessions are disabled by default. If enabled they can drastically reduce
  348. performance, especially on systems processing lots of tasks. This option is useful
  349. on low-traffic workers that experience errors as a result of cached database connections
  350. going stale through inactivity. For example, intermittent errors like
  351. `(OperationalError) (2006, 'MySQL server has gone away')` can be fixed by enabling
  352. short lived sessions. This option only affects the database backend.
  353. .. setting:: sqlalchemy_table_names
  354. sqlalchemy_table_names
  355. ~~~~~~~~~~~~~~~~~~~~~~
  356. When SQLAlchemy is configured as the result backend, Celery automatically
  357. creates two tables to store result metadata for tasks. This setting allows
  358. you to customize the table names:
  359. .. code-block:: python
  360. # use custom table names for the database result backend.
  361. sqlalchemy_table_names = {
  362. 'task': 'myapp_taskmeta',
  363. 'group': 'myapp_groupmeta',
  364. }
  365. .. _conf-rpc-result-backend:
  366. RPC backend settings
  367. --------------------
  368. .. setting:: result_persistent
  369. result_persistent
  370. ~~~~~~~~~~~~~~~~~
  371. If set to :const:`True`, result messages will be persistent. This means the
  372. messages will not be lost after a broker restart. The default is for the
  373. results to be transient.
  374. Example configuration
  375. ~~~~~~~~~~~~~~~~~~~~~
  376. .. code-block:: python
  377. result_backend = 'rpc://'
  378. result_persistent = False
  379. .. _conf-cache-result-backend:
  380. Cache backend settings
  381. ----------------------
  382. .. note::
  383. The cache backend supports the `pylibmc`_ and `python-memcached`
  384. libraries. The latter is used only if `pylibmc`_ is not installed.
  385. Using a single memcached server:
  386. .. code-block:: python
  387. result_backend = 'cache+memcached://127.0.0.1:11211/'
  388. Using multiple memcached servers:
  389. .. code-block:: python
  390. result_backend = """
  391. cache+memcached://172.19.26.240:11211;172.19.26.242:11211/
  392. """.strip()
  393. The "memory" backend stores the cache in memory only:
  394. .. code-block:: python
  395. result_backend = 'cache'
  396. cache_backend = 'memory'
  397. .. setting:: cache_backend_options
  398. cache_backend_options
  399. ~~~~~~~~~~~~~~~~~~~~~
  400. You can set pylibmc options using the :setting:`cache_backend_options`
  401. setting:
  402. .. code-block:: python
  403. cache_backend_options = {
  404. 'binary': True,
  405. 'behaviors': {'tcp_nodelay': True},
  406. }
  407. .. _`pylibmc`: http://sendapatch.se/projects/pylibmc/
  408. .. setting:: cache_backend
  409. cache_backend
  410. ~~~~~~~~~~~~~
  411. This setting is no longer used as it's now possible to specify
  412. the cache backend directly in the :setting:`result_backend` setting.
  413. .. _conf-redis-result-backend:
  414. Redis backend settings
  415. ----------------------
  416. Configuring the backend URL
  417. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  418. .. note::
  419. The Redis backend requires the :mod:`redis` library:
  420. http://pypi.python.org/pypi/redis/
  421. To install the redis package use `pip` or `easy_install`:
  422. .. code-block:: console
  423. $ pip install redis
  424. This backend requires the :setting:`result_backend`
  425. setting to be set to a Redis URL::
  426. result_backend = 'redis://:password@host:port/db'
  427. For example::
  428. result_backend = 'redis://localhost/0'
  429. which is the same as::
  430. result_backend = 'redis://'
  431. The fields of the URL are defined as follows:
  432. - *host*
  433. Host name or IP address of the Redis server. e.g. `localhost`.
  434. - *port*
  435. Port to the Redis server. Default is 6379.
  436. - *db*
  437. Database number to use. Default is 0.
  438. The db can include an optional leading slash.
  439. - *password*
  440. Password used to connect to the database.
  441. .. setting:: redis_max_connections
  442. redis_max_connections
  443. ~~~~~~~~~~~~~~~~~~~~~
  444. Maximum number of connections available in the Redis connection
  445. pool used for sending and retrieving results.
  446. .. setting:: redis_socket_timeout
  447. redis_socket_timeout
  448. ~~~~~~~~~~~~~~~~~~~~
  449. Socket timeout for connections to Redis from the result backend
  450. in seconds (int/float)
  451. Default is 5 seconds.
  452. .. _conf-mongodb-result-backend:
  453. MongoDB backend settings
  454. ------------------------
  455. .. note::
  456. The MongoDB backend requires the :mod:`pymongo` library:
  457. http://github.com/mongodb/mongo-python-driver/tree/master
  458. .. setting:: mongodb_backend_settings
  459. mongodb_backend_settings
  460. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  461. This is a dict supporting the following keys:
  462. * database
  463. The database name to connect to. Defaults to ``celery``.
  464. * taskmeta_collection
  465. The collection name to store task meta data.
  466. Defaults to ``celery_taskmeta``.
  467. * max_pool_size
  468. Passed as max_pool_size to PyMongo's Connection or MongoClient
  469. constructor. It is the maximum number of TCP connections to keep
  470. open to MongoDB at a given time. If there are more open connections
  471. than max_pool_size, sockets will be closed when they are released.
  472. Defaults to 10.
  473. * options
  474. Additional keyword arguments to pass to the mongodb connection
  475. constructor. See the :mod:`pymongo` docs to see a list of arguments
  476. supported.
  477. .. _example-mongodb-result-config:
  478. Example configuration
  479. ~~~~~~~~~~~~~~~~~~~~~
  480. .. code-block:: python
  481. result_backend = 'mongodb://192.168.1.100:30000/'
  482. mongodb_backend_settings = {
  483. 'database': 'mydb',
  484. 'taskmeta_collection': 'my_taskmeta_collection',
  485. }
  486. .. _conf-cassandra-result-backend:
  487. cassandra backend settings
  488. --------------------------
  489. .. note::
  490. This Cassandra backend driver requires :mod:`cassandra-driver`.
  491. https://pypi.python.org/pypi/cassandra-driver
  492. To install, use `pip` or `easy_install`:
  493. .. code-block:: bash
  494. $ pip install cassandra-driver
  495. This backend requires the following configuration directives to be set.
  496. .. setting:: cassandra_servers
  497. cassandra_servers
  498. ~~~~~~~~~~~~~~~~~
  499. List of ``host`` Cassandra servers. e.g.::
  500. cassandra_servers = ['localhost']
  501. .. setting:: cassandra_port
  502. cassandra_port
  503. ~~~~~~~~~~~~~~
  504. Port to contact the Cassandra servers on. Default is 9042.
  505. .. setting:: cassandra_keyspace
  506. cassandra_keyspace
  507. ~~~~~~~~~~~~~~~~~~
  508. The keyspace in which to store the results. e.g.::
  509. cassandra_keyspace = 'tasks_keyspace'
  510. .. setting:: cassandra_table
  511. cassandra_table
  512. ~~~~~~~~~~~~~~~
  513. The table (column family) in which to store the results. e.g.::
  514. cassandra_table = 'tasks'
  515. .. setting:: cassandra_read_consistency
  516. cassandra_read_consistency
  517. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  518. The read consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``,
  519. ``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``.
  520. .. setting:: cassandra_write_consistency
  521. cassandra_write_consistency
  522. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  523. The write consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``,
  524. ``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``.
  525. .. setting:: cassandra_entry_ttl
  526. cassandra_entry_ttl
  527. ~~~~~~~~~~~~~~~~~~~
  528. Time-to-live for status entries. They will expire and be removed after that many seconds
  529. after adding. Default (None) means they will never expire.
  530. Example configuration
  531. ~~~~~~~~~~~~~~~~~~~~~
  532. .. code-block:: python
  533. cassandra_servers = ['localhost']
  534. cassandra_keyspace = 'celery'
  535. cassandra_table = 'tasks'
  536. cassandra_read_consistency = 'ONE'
  537. cassandra_write_consistency = 'ONE'
  538. cassandra_entry_ttl = 86400
  539. .. _conf-riak-result-backend:
  540. Riak backend settings
  541. ---------------------
  542. .. note::
  543. The Riak backend requires the :mod:`riak` library:
  544. http://pypi.python.org/pypi/riak/
  545. To install the riak package use `pip` or `easy_install`:
  546. .. code-block:: console
  547. $ pip install riak
  548. This backend requires the :setting:`result_backend`
  549. setting to be set to a Riak URL::
  550. result_backend = "riak://host:port/bucket"
  551. For example::
  552. result_backend = "riak://localhost/celery
  553. which is the same as::
  554. result_backend = "riak://"
  555. The fields of the URL are defined as follows:
  556. - *host*
  557. Host name or IP address of the Riak server. e.g. `"localhost"`.
  558. - *port*
  559. Port to the Riak server using the protobuf protocol. Default is 8087.
  560. - *bucket*
  561. Bucket name to use. Default is `celery`.
  562. The bucket needs to be a string with ascii characters only.
  563. Altenatively, this backend can be configured with the following configuration directives.
  564. .. setting:: riak_backend_settings
  565. riak_backend_settings
  566. ~~~~~~~~~~~~~~~~~~~~~
  567. This is a dict supporting the following keys:
  568. * host
  569. The host name of the Riak server. Defaults to "localhost".
  570. * port
  571. The port the Riak server is listening to. Defaults to 8087.
  572. * bucket
  573. The bucket name to connect to. Defaults to "celery".
  574. * protocol
  575. The protocol to use to connect to the Riak server. This is not configurable
  576. via :setting:`result_backend`
  577. .. _conf-ironcache-result-backend:
  578. IronCache backend settings
  579. --------------------------
  580. .. note::
  581. The IronCache backend requires the :mod:`iron_celery` library:
  582. http://pypi.python.org/pypi/iron_celery
  583. To install the iron_celery package use `pip` or `easy_install`:
  584. .. code-block:: console
  585. $ pip install iron_celery
  586. IronCache is configured via the URL provided in :setting:`result_backend`, for example::
  587. result_backend = 'ironcache://project_id:token@'
  588. Or to change the cache name::
  589. ironcache:://project_id:token@/awesomecache
  590. For more information, see: https://github.com/iron-io/iron_celery
  591. .. _conf-couchbase-result-backend:
  592. Couchbase backend settings
  593. --------------------------
  594. .. note::
  595. The Couchbase backend requires the :mod:`couchbase` library:
  596. https://pypi.python.org/pypi/couchbase
  597. To install the couchbase package use `pip` or `easy_install`:
  598. .. code-block:: console
  599. $ pip install couchbase
  600. This backend can be configured via the :setting:`result_backend`
  601. set to a couchbase URL::
  602. result_backend = 'couchbase://username:password@host:port/bucket'
  603. .. setting:: couchbase_backend_settings
  604. couchbase_backend_settings
  605. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  606. This is a dict supporting the following keys:
  607. * host
  608. Host name of the Couchbase server. Defaults to ``localhost``.
  609. * port
  610. The port the Couchbase server is listening to. Defaults to ``8091``.
  611. * bucket
  612. The default bucket the Couchbase server is writing to.
  613. Defaults to ``default``.
  614. * username
  615. User name to authenticate to the Couchbase server as (optional).
  616. * password
  617. Password to authenticate to the Couchbase server (optional).
  618. .. _conf-couchdb-result-backend:
  619. CouchDB backend settings
  620. ------------------------
  621. .. note::
  622. The CouchDB backend requires the :mod:`pycouchdb` library:
  623. https://pypi.python.org/pypi/pycouchdb
  624. To install the couchbase package use `pip` or `easy_install`:
  625. .. code-block:: console
  626. $ pip install pycouchdb
  627. This backend can be configured via the :setting:`result_backend`
  628. set to a couchdb URL::
  629. result_backend = 'couchdb://username:password@host:port/container'
  630. The URL is formed out of the following parts:
  631. * username
  632. User name to authenticate to the CouchDB server as (optional).
  633. * password
  634. Password to authenticate to the CouchDB server (optional).
  635. * host
  636. Host name of the CouchDB server. Defaults to ``localhost``.
  637. * port
  638. The port the CouchDB server is listening to. Defaults to ``8091``.
  639. * container
  640. The default container the CouchDB server is writing to.
  641. Defaults to ``default``.
  642. .. _conf-amqp-result-backend:
  643. AMQP backend settings
  644. ---------------------
  645. .. admonition:: Do not use in production.
  646. This is the old AMQP result backend that creates one queue per task,
  647. if you want to send results back as message please consider using the
  648. RPC backend instead, or if you need the results to be persistent
  649. use a result backend designed for that purpose (e.g. Redis, or a database).
  650. .. note::
  651. The AMQP backend requires RabbitMQ 1.1.0 or higher to automatically
  652. expire results. If you are running an older version of RabbitMQ
  653. you should disable result expiration like this:
  654. result_expires = None
  655. .. setting:: result_exchange
  656. result_exchange
  657. ~~~~~~~~~~~~~~~
  658. Name of the exchange to publish results in. Default is `celeryresults`.
  659. .. setting:: result_exchange_type
  660. result_exchange_type
  661. ~~~~~~~~~~~~~~~~~~~~
  662. The exchange type of the result exchange. Default is to use a `direct`
  663. exchange.
  664. result_persistent
  665. ~~~~~~~~~~~~~~~~~
  666. If set to :const:`True`, result messages will be persistent. This means the
  667. messages will not be lost after a broker restart. The default is for the
  668. results to be transient.
  669. Example configuration
  670. ~~~~~~~~~~~~~~~~~~~~~
  671. .. code-block:: python
  672. result_backend = 'amqp'
  673. result_expires = 18000 # 5 hours.
  674. .. _conf-messaging:
  675. Message Routing
  676. ---------------
  677. .. _conf-messaging-routing:
  678. .. setting:: task_queues
  679. task_queues
  680. ~~~~~~~~~~~
  681. Most users will not want to specify this setting and should rather use
  682. the :ref:`automatic routing facilities <routing-automatic>`.
  683. If you really want to configure advanced routing, this setting should
  684. be a list of :class:`kombu.Queue` objects the worker will consume from.
  685. Note that workers can be overriden this setting via the `-Q` option,
  686. or individual queues from this list (by name) can be excluded using
  687. the `-X` option.
  688. Also see :ref:`routing-basics` for more information.
  689. The default is a queue/exchange/binding key of ``celery``, with
  690. exchange type ``direct``.
  691. See also :setting:`task_routes`
  692. .. setting:: task_routes
  693. task_routes
  694. ~~~~~~~~~~~~~
  695. A list of routers, or a single router used to route tasks to queues.
  696. When deciding the final destination of a task the routers are consulted
  697. in order.
  698. A router can be specified as either:
  699. * A router class instances
  700. * A string which provides the path to a router class
  701. * A dict containing router specification. It will be converted to a :class:`celery.routes.MapRoute` instance.
  702. Examples:
  703. .. code-block:: python
  704. task_routes = {
  705. "celery.ping": "default",
  706. "mytasks.add": "cpu-bound",
  707. "video.encode": {
  708. "queue": "video",
  709. "exchange": "media"
  710. "routing_key": "media.video.encode",
  711. },
  712. }
  713. task_routes = ("myapp.tasks.Router", {"celery.ping": "default})
  714. Where ``myapp.tasks.Router`` could be:
  715. .. code-block:: python
  716. class Router(object):
  717. def route_for_task(self, task, args=None, kwargs=None):
  718. if task == "celery.ping":
  719. return "default"
  720. ``route_for_task`` may return a string or a dict. A string then means
  721. it's a queue name in :setting:`task_queues`, a dict means it's a custom route.
  722. When sending tasks, the routers are consulted in order. The first
  723. router that doesn't return ``None`` is the route to use. The message options
  724. is then merged with the found route settings, where the routers settings
  725. have priority.
  726. Example if :func:`~celery.execute.apply_async` has these arguments:
  727. .. code-block:: python
  728. Task.apply_async(immediate=False, exchange="video",
  729. routing_key="video.compress")
  730. and a router returns:
  731. .. code-block:: python
  732. {"immediate": True, "exchange": "urgent"}
  733. the final message options will be:
  734. .. code-block:: python
  735. immediate=True, exchange="urgent", routing_key="video.compress"
  736. (and any default message options defined in the
  737. :class:`~celery.task.base.Task` class)
  738. Values defined in :setting:`task_routes` have precedence over values defined in
  739. :setting:`task_queues` when merging the two.
  740. With the follow settings:
  741. .. code-block:: python
  742. task_queues = {
  743. "cpubound": {
  744. "exchange": "cpubound",
  745. "routing_key": "cpubound",
  746. },
  747. }
  748. task_routes = {
  749. "tasks.add": {
  750. "queue": "cpubound",
  751. "routing_key": "tasks.add",
  752. "serializer": "json",
  753. },
  754. }
  755. The final routing options for ``tasks.add`` will become:
  756. .. code-block:: javascript
  757. {"exchange": "cpubound",
  758. "routing_key": "tasks.add",
  759. "serializer": "json"}
  760. See :ref:`routers` for more examples.
  761. .. setting:: task_queue_ha_policy
  762. task_queue_ha_policy
  763. ~~~~~~~~~~~~~~~~~~~~
  764. :brokers: RabbitMQ
  765. This will set the default HA policy for a queue, and the value
  766. can either be a string (usually ``all``):
  767. .. code-block:: python
  768. task_queue_ha_policy = 'all'
  769. Using 'all' will replicate the queue to all current nodes,
  770. Or you can give it a list of nodes to replicate to:
  771. .. code-block:: python
  772. task_queue_ha_policy = ['rabbit@host1', 'rabbit@host2']
  773. Using a list will implicitly set ``x-ha-policy`` to 'nodes' and
  774. ``x-ha-policy-params`` to the given list of nodes.
  775. See http://www.rabbitmq.com/ha.html for more information.
  776. .. setting:: worker_direct
  777. worker_direct
  778. ~~~~~~~~~~~~~
  779. This option enables so that every worker has a dedicated queue,
  780. so that tasks can be routed to specific workers.
  781. The queue name for each worker is automatically generated based on
  782. the worker hostname and a ``.dq`` suffix, using the ``C.dq`` exchange.
  783. For example the queue name for the worker with node name ``w1@example.com``
  784. becomes::
  785. w1@example.com.dq
  786. Then you can route the task to the task by specifying the hostname
  787. as the routing key and the ``C.dq`` exchange::
  788. task_routes = {
  789. 'tasks.add': {'exchange': 'C.dq', 'routing_key': 'w1@example.com'}
  790. }
  791. .. setting:: task_create_missing_queues
  792. task_create_missing_queues
  793. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  794. If enabled (default), any queues specified that are not defined in
  795. :setting:`task_queues` will be automatically created. See
  796. :ref:`routing-automatic`.
  797. .. setting:: task_default_queue
  798. task_default_queue
  799. ~~~~~~~~~~~~~~~~~~
  800. The name of the default queue used by `.apply_async` if the message has
  801. no route or no custom queue has been specified.
  802. This queue must be listed in :setting:`task_queues`.
  803. If :setting:`task_queues` is not specified then it is automatically
  804. created containing one queue entry, where this name is used as the name of
  805. that queue.
  806. The default is: `celery`.
  807. .. seealso::
  808. :ref:`routing-changing-default-queue`
  809. .. setting:: task_default_exchange
  810. task_default_exchange
  811. ~~~~~~~~~~~~~~~~~~~~~
  812. Name of the default exchange to use when no custom exchange is
  813. specified for a key in the :setting:`task_queues` setting.
  814. The default is: `celery`.
  815. .. setting:: task_default_exchange_type
  816. task_default_exchange_type
  817. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  818. Default exchange type used when no custom exchange type is specified
  819. for a key in the :setting:`task_queues` setting.
  820. The default is: `direct`.
  821. .. setting:: task_default_routing_key
  822. task_default_routing_key
  823. ~~~~~~~~~~~~~~~~~~~~~~~~
  824. The default routing key used when no custom routing key
  825. is specified for a key in the :setting:`task_queues` setting.
  826. The default is: `celery`.
  827. .. setting:: task_default_delivery_mode
  828. task_default_delivery_mode
  829. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  830. Can be `transient` or `persistent`. The default is to send
  831. persistent messages.
  832. .. _conf-broker-settings:
  833. Broker Settings
  834. ---------------
  835. .. setting:: broker_url
  836. broker_url
  837. ~~~~~~~~~~
  838. Default broker URL. This must be an URL in the form of::
  839. transport://userid:password@hostname:port/virtual_host
  840. Only the scheme part (``transport://``) is required, the rest
  841. is optional, and defaults to the specific transports default values.
  842. The transport part is the broker implementation to use, and the
  843. default is ``amqp``, which uses ``librabbitmq`` by default or falls back to
  844. ``pyamqp`` if that is not installed. Also there are many other choices including
  845. ``redis``, ``beanstalk``, ``sqlalchemy``, ``django``, ``mongodb``,
  846. ``couchdb``.
  847. It can also be a fully qualified path to your own transport implementation.
  848. More than broker URL, of the same transport, can also be specified.
  849. The broker URLs can be passed in as a single string that is semicolon delimited::
  850. broker_url = 'transport://userid:password@hostname:port//;transport://userid:password@hostname:port//'
  851. Or as a list::
  852. broker_url = [
  853. 'transport://userid:password@localhost:port//',
  854. 'transport://userid:password@hostname:port//'
  855. ]
  856. The brokers will then be used in the :setting:`broker_failover_strategy`.
  857. See :ref:`kombu:connection-urls` in the Kombu documentation for more
  858. information.
  859. .. setting:: broker_failover_strategy
  860. broker_failover_strategy
  861. ~~~~~~~~~~~~~~~~~~~~~~~~
  862. Default failover strategy for the broker Connection object. If supplied,
  863. may map to a key in 'kombu.connection.failover_strategies', or be a reference
  864. to any method that yields a single item from a supplied list.
  865. Example::
  866. # Random failover strategy
  867. def random_failover_strategy(servers):
  868. it = list(it) # don't modify callers list
  869. shuffle = random.shuffle
  870. for _ in repeat(None):
  871. shuffle(it)
  872. yield it[0]
  873. broker_failover_strategy = random_failover_strategy
  874. .. setting:: broker_heartbeat
  875. broker_heartbeat
  876. ~~~~~~~~~~~~~~~~
  877. :transports supported: ``pyamqp``
  878. It's not always possible to detect connection loss in a timely
  879. manner using TCP/IP alone, so AMQP defines something called heartbeats
  880. that's is used both by the client and the broker to detect if
  881. a connection was closed.
  882. Heartbeats are disabled by default.
  883. If the heartbeat value is 10 seconds, then
  884. the heartbeat will be monitored at the interval specified
  885. by the :setting:`broker_heartbeat_checkrate` setting, which by default is
  886. double the rate of the heartbeat value
  887. (so for the default 10 seconds, the heartbeat is checked every 5 seconds).
  888. .. setting:: broker_heartbeat_checkrate
  889. broker_heartbeat_checkrate
  890. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  891. :transports supported: ``pyamqp``
  892. At intervals the worker will monitor that the broker has not missed
  893. too many heartbeats. The rate at which this is checked is calculated
  894. by dividing the :setting:`broker_heartbeat` value with this value,
  895. so if the heartbeat is 10.0 and the rate is the default 2.0, the check
  896. will be performed every 5 seconds (twice the heartbeat sending rate).
  897. .. setting:: broker_use_ssl
  898. broker_use_ssl
  899. ~~~~~~~~~~~~~~
  900. :transports supported: ``pyamqp``, ``redis``
  901. Toggles SSL usage on broker connection and SSL settings.
  902. If ``True`` the connection will use SSL with default SSL settings.
  903. If set to a dict, will configure SSL connection according to the specified
  904. policy. The format used is python `ssl.wrap_socket()
  905. options <https://docs.python.org/3/library/ssl.html#ssl.wrap_socket>`_.
  906. Default is ``False`` (no SSL).
  907. Note that SSL socket is generally served on a separate port by the broker.
  908. Example providing a client cert and validating the server cert against a custom
  909. certificate authority:
  910. .. code-block:: python
  911. import ssl
  912. broker_use_ssl = {
  913. 'keyfile': '/var/ssl/private/worker-key.pem',
  914. 'certfile': '/var/ssl/amqp-server-cert.pem',
  915. 'ca_certs': '/var/ssl/myca.pem',
  916. 'cert_reqs': ssl.CERT_REQUIRED
  917. }
  918. .. warning::
  919. Be careful using ``broker_use_ssl=True``, it is possible that your default
  920. configuration do not validate the server cert at all, please read Python
  921. `ssl module security
  922. considerations <https://docs.python.org/3/library/ssl.html#ssl-security>`_.
  923. .. setting:: broker_pool_limit
  924. broker_pool_limit
  925. ~~~~~~~~~~~~~~~~~
  926. .. versionadded:: 2.3
  927. The maximum number of connections that can be open in the connection pool.
  928. The pool is enabled by default since version 2.5, with a default limit of ten
  929. connections. This number can be tweaked depending on the number of
  930. threads/greenthreads (eventlet/gevent) using a connection. For example
  931. running eventlet with 1000 greenlets that use a connection to the broker,
  932. contention can arise and you should consider increasing the limit.
  933. If set to :const:`None` or 0 the connection pool will be disabled and
  934. connections will be established and closed for every use.
  935. Default (since 2.5) is to use a pool of 10 connections.
  936. .. setting:: broker_connection_timeout
  937. broker_connection_timeout
  938. ~~~~~~~~~~~~~~~~~~~~~~~~~
  939. The default timeout in seconds before we give up establishing a connection
  940. to the AMQP server. Default is 4 seconds.
  941. .. setting:: broker_connection_retry
  942. broker_connection_retry
  943. ~~~~~~~~~~~~~~~~~~~~~~~
  944. Automatically try to re-establish the connection to the AMQP broker if lost.
  945. The time between retries is increased for each retry, and is
  946. not exhausted before :setting:`broker_connection_max_retries` is
  947. exceeded.
  948. This behavior is on by default.
  949. .. setting:: broker_connection_max_retries
  950. broker_connection_max_retries
  951. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  952. Maximum number of retries before we give up re-establishing a connection
  953. to the AMQP broker.
  954. If this is set to :const:`0` or :const:`None`, we will retry forever.
  955. Default is 100 retries.
  956. .. setting:: broker_login_method
  957. broker_login_method
  958. ~~~~~~~~~~~~~~~~~~~
  959. Set custom amqp login method, default is ``AMQPLAIN``.
  960. .. setting:: broker_transport_options
  961. broker_transport_options
  962. ~~~~~~~~~~~~~~~~~~~~~~~~
  963. .. versionadded:: 2.2
  964. A dict of additional options passed to the underlying transport.
  965. See your transport user manual for supported options (if any).
  966. Example setting the visibility timeout (supported by Redis and SQS
  967. transports):
  968. .. code-block:: python
  969. broker_transport_options = {'visibility_timeout': 18000} # 5 hours
  970. .. _conf-worker:
  971. Worker
  972. ------
  973. .. setting:: imports
  974. imports
  975. ~~~~~~~
  976. A sequence of modules to import when the worker starts.
  977. This is used to specify the task modules to import, but also
  978. to import signal handlers and additional remote control commands, etc.
  979. The modules will be imported in the original order.
  980. .. setting:: include
  981. include
  982. ~~~~~~~
  983. Exact same semantics as :setting:`imports`, but can be used as a means
  984. to have different import categories.
  985. The modules in this setting are imported after the modules in
  986. :setting:`imports`.
  987. .. _conf-concurrency:
  988. .. setting:: worker_concurrency
  989. worker_concurrency
  990. ~~~~~~~~~~~~~~~~~~
  991. The number of concurrent worker processes/threads/green threads executing
  992. tasks.
  993. If you're doing mostly I/O you can have more processes,
  994. but if mostly CPU-bound, try to keep it close to the
  995. number of CPUs on your machine. If not set, the number of CPUs/cores
  996. on the host will be used.
  997. Defaults to the number of available CPUs.
  998. .. setting:: worker_prefetch_multiplier
  999. worker_prefetch_multiplier
  1000. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1001. How many messages to prefetch at a time multiplied by the number of
  1002. concurrent processes. The default is 4 (four messages for each
  1003. process). The default setting is usually a good choice, however -- if you
  1004. have very long running tasks waiting in the queue and you have to start the
  1005. workers, note that the first worker to start will receive four times the
  1006. number of messages initially. Thus the tasks may not be fairly distributed
  1007. to the workers.
  1008. To disable prefetching, set :setting:`worker_prefetch_multiplier` to 1.
  1009. Changing that setting to 0 will allow the worker to keep consuming
  1010. as many messages as it wants.
  1011. For more on prefetching, read :ref:`optimizing-prefetch-limit`
  1012. .. note::
  1013. Tasks with ETA/countdown are not affected by prefetch limits.
  1014. .. setting:: worker_lost_wait
  1015. worker_lost_wait
  1016. ~~~~~~~~~~~~~~~~
  1017. In some cases a worker may be killed without proper cleanup,
  1018. and the worker may have published a result before terminating.
  1019. This value specifies how long we wait for any missing results before
  1020. raising a :exc:`@WorkerLostError` exception.
  1021. Default is 10.0
  1022. .. setting:: worker_max_tasks_per_child
  1023. worker_max_tasks_per_child
  1024. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1025. Maximum number of tasks a pool worker process can execute before
  1026. it's replaced with a new one. Default is no limit.
  1027. .. setting:: worker_max_memory_per_child
  1028. worker_max_memory_per_child
  1029. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1030. Maximum amount of resident memory that may be consumed by a
  1031. worker before it will be replaced by a new worker. If a single
  1032. task causes a worker to exceed this limit, the task will be
  1033. completed, and the worker will be replaced afterwards. Default:
  1034. no limit.
  1035. .. setting:: worker_disable_rate_limits
  1036. worker_disable_rate_limits
  1037. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1038. Disable all rate limits, even if tasks has explicit rate limits set.
  1039. .. setting:: worker_state_db
  1040. worker_state_db
  1041. ~~~~~~~~~~~~~~~
  1042. Name of the file used to stores persistent worker state (like revoked tasks).
  1043. Can be a relative or absolute path, but be aware that the suffix `.db`
  1044. may be appended to the file name (depending on Python version).
  1045. Can also be set via the :option:`--statedb` argument to
  1046. :mod:`~celery.bin.worker`.
  1047. Not enabled by default.
  1048. .. setting:: worker_timer_precision
  1049. worker_timer_precision
  1050. ~~~~~~~~~~~~~~~~~~~~~~
  1051. Set the maximum time in seconds that the ETA scheduler can sleep between
  1052. rechecking the schedule. Default is 1 second.
  1053. Setting this value to 1 second means the schedulers precision will
  1054. be 1 second. If you need near millisecond precision you can set this to 0.1.
  1055. .. setting:: worker_enable_remote_control
  1056. worker_enable_remote_control
  1057. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1058. Specify if remote control of the workers is enabled.
  1059. Default is :const:`True`.
  1060. .. _conf-error-mails:
  1061. Error E-Mails
  1062. -------------
  1063. .. setting:: task_send_error_emails
  1064. task_send_error_emails
  1065. ~~~~~~~~~~~~~~~~~~~~~~
  1066. The default value for the `Task.send_error_emails` attribute, which if
  1067. set to :const:`True` means errors occurring during task execution will be
  1068. sent to :setting:`admins` by email.
  1069. Disabled by default.
  1070. .. setting:: admins
  1071. admins
  1072. ~~~~~~
  1073. List of `(name, email_address)` tuples for the administrators that should
  1074. receive error emails.
  1075. .. setting:: server_email
  1076. server_email
  1077. ~~~~~~~~~~~~
  1078. The email address this worker sends emails from.
  1079. Default is celery@localhost.
  1080. .. setting:: email_host
  1081. email_host
  1082. ~~~~~~~~~~
  1083. The mail server to use. Default is ``localhost``.
  1084. .. setting:: email_host_user
  1085. email_host_user
  1086. ~~~~~~~~~~~~~~~
  1087. User name (if required) to log on to the mail server with.
  1088. .. setting:: email_host_password
  1089. email_host_password
  1090. ~~~~~~~~~~~~~~~~~~~
  1091. Password (if required) to log on to the mail server with.
  1092. .. setting:: email_port
  1093. email_port
  1094. ~~~~~~~~~~
  1095. The port the mail server is listening on. Default is `25`.
  1096. .. setting:: email_use_ssl
  1097. email_use_ssl
  1098. ~~~~~~~~~~~~~
  1099. Use SSL when connecting to the SMTP server. Disabled by default.
  1100. .. setting:: email_use_tls
  1101. email_use_tls
  1102. ~~~~~~~~~~~~~
  1103. Use TLS when connecting to the SMTP server. Disabled by default.
  1104. .. setting:: email_timeout
  1105. email_timeout
  1106. ~~~~~~~~~~~~~
  1107. Timeout in seconds for when we give up trying to connect
  1108. to the SMTP server when sending emails.
  1109. The default is 2 seconds.
  1110. .. setting:: email_charset
  1111. email_charset
  1112. ~~~~~~~~~~~~~
  1113. .. versionadded:: 4.0
  1114. Charset for outgoing emails. Default is "us-ascii".
  1115. .. _conf-example-error-mail-config:
  1116. Example E-Mail configuration
  1117. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1118. This configuration enables the sending of error emails to
  1119. george@vandelay.com and kramer@vandelay.com:
  1120. .. code-block:: python
  1121. # Enables error emails.
  1122. task_send_error_emails = True
  1123. # Name and email addresses of recipients
  1124. admins = (
  1125. ('George Costanza', 'george@vandelay.com'),
  1126. ('Cosmo Kramer', 'kosmo@vandelay.com'),
  1127. )
  1128. # Email address used as sender (From field).
  1129. server_email = 'no-reply@vandelay.com'
  1130. # Mailserver configuration
  1131. email_host = 'mail.vandelay.com'
  1132. email_port = 25
  1133. # email_host_user = 'servers'
  1134. # email_host_password = 's3cr3t'
  1135. .. _conf-events:
  1136. Events
  1137. ------
  1138. .. setting:: worker_send_events
  1139. worker_send_events
  1140. ~~~~~~~~~~~~~~~~~~
  1141. Send task-related events so that tasks can be monitored using tools like
  1142. `flower`. Sets the default value for the workers :option:`-E` argument.
  1143. .. setting:: task_send_sent_event
  1144. task_send_sent_event
  1145. ~~~~~~~~~~~~~~~~~~~~
  1146. .. versionadded:: 2.2
  1147. If enabled, a :event:`task-sent` event will be sent for every task so tasks can be
  1148. tracked before they are consumed by a worker.
  1149. Disabled by default.
  1150. .. setting:: event_queue_ttl
  1151. event_queue_ttl
  1152. ~~~~~~~~~~~~~~~~~~~~~~
  1153. :transports supported: ``amqp``
  1154. Message expiry time in seconds (int/float) for when messages sent to a monitor clients
  1155. event queue is deleted (``x-message-ttl``)
  1156. For example, if this value is set to 10 then a message delivered to this queue
  1157. will be deleted after 10 seconds.
  1158. Disabled by default.
  1159. .. setting:: event_queue_expires
  1160. event_queue_expires
  1161. ~~~~~~~~~~~~~~~~~~~
  1162. :transports supported: ``amqp``
  1163. Expiry time in seconds (int/float) for when after a monitor clients
  1164. event queue will be deleted (``x-expires``).
  1165. Default is never, relying on the queue autodelete setting.
  1166. .. setting:: event_serializer
  1167. event_serializer
  1168. ~~~~~~~~~~~~~~~~
  1169. Message serialization format used when sending event messages.
  1170. Default is ``json``. See :ref:`calling-serializers`.
  1171. .. _conf-logging:
  1172. Logging
  1173. -------
  1174. .. setting:: worker_hijack_root_logger
  1175. worker_hijack_root_logger
  1176. ~~~~~~~~~~~~~~~~~~~~~~~~~
  1177. .. versionadded:: 2.2
  1178. By default any previously configured handlers on the root logger will be
  1179. removed. If you want to customize your own logging handlers, then you
  1180. can disable this behavior by setting
  1181. `worker_hijack_root_logger = False`.
  1182. .. note::
  1183. Logging can also be customized by connecting to the
  1184. :signal:`celery.signals.setup_logging` signal.
  1185. .. setting:: worker_log_color
  1186. worker_log_color
  1187. ~~~~~~~~~~~~~~~~~
  1188. Enables/disables colors in logging output by the Celery apps.
  1189. By default colors are enabled if
  1190. 1) the app is logging to a real terminal, and not a file.
  1191. 2) the app is not running on Windows.
  1192. .. setting:: worker_log_format
  1193. worker_log_format
  1194. ~~~~~~~~~~~~~~~~~
  1195. The format to use for log messages.
  1196. Default is `[%(asctime)s: %(levelname)s/%(processName)s] %(message)s`
  1197. See the Python :mod:`logging` module for more information about log
  1198. formats.
  1199. .. setting:: worker_task_log_format
  1200. worker_task_log_format
  1201. ~~~~~~~~~~~~~~~~~~~~~~
  1202. The format to use for log messages logged in tasks. Can be overridden using
  1203. the :option:`--loglevel` option to :mod:`~celery.bin.worker`.
  1204. Default is::
  1205. [%(asctime)s: %(levelname)s/%(processName)s]
  1206. [%(task_name)s(%(task_id)s)] %(message)s
  1207. See the Python :mod:`logging` module for more information about log
  1208. formats.
  1209. .. setting:: worker_redirect_stdouts
  1210. worker_redirect_stdouts
  1211. ~~~~~~~~~~~~~~~~~~~~~~~
  1212. If enabled `stdout` and `stderr` will be redirected
  1213. to the current logger.
  1214. Enabled by default.
  1215. Used by :program:`celery worker` and :program:`celery beat`.
  1216. .. setting:: worker_redirect_stdouts_level
  1217. worker_redirect_stdouts_level
  1218. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1219. The log level output to `stdout` and `stderr` is logged as.
  1220. Can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
  1221. :const:`ERROR` or :const:`CRITICAL`.
  1222. Default is :const:`WARNING`.
  1223. .. _conf-security:
  1224. Security
  1225. --------
  1226. .. setting:: security_key
  1227. security_key
  1228. ~~~~~~~~~~~~
  1229. .. versionadded:: 2.5
  1230. The relative or absolute path to a file containing the private key
  1231. used to sign messages when :ref:`message-signing` is used.
  1232. .. setting:: security_certificate
  1233. security_certificate
  1234. ~~~~~~~~~~~~~~~~~~~~
  1235. .. versionadded:: 2.5
  1236. The relative or absolute path to an X.509 certificate file
  1237. used to sign messages when :ref:`message-signing` is used.
  1238. .. setting:: security_cert_store
  1239. security_cert_store
  1240. ~~~~~~~~~~~~~~~~~~~
  1241. .. versionadded:: 2.5
  1242. The directory containing X.509 certificates used for
  1243. :ref:`message-signing`. Can be a glob with wildcards,
  1244. (for example :file:`/etc/certs/*.pem`).
  1245. .. _conf-custom-components:
  1246. Custom Component Classes (advanced)
  1247. -----------------------------------
  1248. .. setting:: worker_pool
  1249. worker_pool
  1250. ~~~~~~~~~~~
  1251. Name of the pool class used by the worker.
  1252. .. admonition:: Eventlet/Gevent
  1253. Never use this option to select the eventlet or gevent pool.
  1254. You must use the `-P` option instead, otherwise the monkey patching
  1255. will happen too late and things will break in strange and silent ways.
  1256. Default is ``celery.concurrency.prefork:TaskPool``.
  1257. .. setting:: worker_pool_restarts
  1258. worker_pool_restarts
  1259. ~~~~~~~~~~~~~~~~~~~~
  1260. If enabled the worker pool can be restarted using the
  1261. :control:`pool_restart` remote control command.
  1262. Disabled by default.
  1263. .. setting:: worker_autoscaler
  1264. worker_autoscaler
  1265. ~~~~~~~~~~~~~~~~~
  1266. .. versionadded:: 2.2
  1267. Name of the autoscaler class to use.
  1268. Default is ``celery.worker.autoscale:Autoscaler``.
  1269. .. setting:: worker_autoreloader
  1270. worker_autoreloader
  1271. ~~~~~~~~~~~~~~~~~~~
  1272. Name of the autoreloader class used by the worker to reload
  1273. Python modules and files that have changed.
  1274. Default is: ``celery.worker.autoreload:Autoreloader``.
  1275. .. setting:: worker_consumer
  1276. worker_consumer
  1277. ~~~~~~~~~~~~~~~
  1278. Name of the consumer class used by the worker.
  1279. Default is :class:`celery.worker.consumer.Consumer`
  1280. .. setting:: worker_timer
  1281. worker_timer
  1282. ~~~~~~~~~~~~
  1283. Name of the ETA scheduler class used by the worker.
  1284. Default is :class:`kombu.async.hub.timer.Timer`, or one overrided
  1285. by the pool implementation.
  1286. .. _conf-celerybeat:
  1287. Beat Settings (:program:`celery beat`)
  1288. --------------------------------------
  1289. .. setting:: beat_schedule
  1290. beat_schedule
  1291. ~~~~~~~~~~~~~
  1292. The periodic task schedule used by :mod:`~celery.bin.beat`.
  1293. See :ref:`beat-entries`.
  1294. .. setting:: beat_scheduler
  1295. beat_scheduler
  1296. ~~~~~~~~~~~~~~
  1297. The default scheduler class. Default is ``celery.beat:PersistentScheduler``.
  1298. Can also be set via the :option:`-S` argument to
  1299. :mod:`~celery.bin.beat`.
  1300. .. setting:: beat_schedule_filename
  1301. beat_schedule_filename
  1302. ~~~~~~~~~~~~~~~~~~~~~~
  1303. Name of the file used by `PersistentScheduler` to store the last run times
  1304. of periodic tasks. Can be a relative or absolute path, but be aware that the
  1305. suffix `.db` may be appended to the file name (depending on Python version).
  1306. Can also be set via the :option:`--schedule` argument to
  1307. :mod:`~celery.bin.beat`.
  1308. .. setting:: beat_sync_every
  1309. beat_sync_every
  1310. ~~~~~~~~~~~~~~~
  1311. The number of periodic tasks that can be called before another database sync
  1312. is issued.
  1313. Defaults to 0 (sync based on timing - default of 3 minutes as determined by
  1314. scheduler.sync_every). If set to 1, beat will call sync after every task
  1315. message sent.
  1316. .. setting:: beat_max_loop_interval
  1317. beat_max_loop_interval
  1318. ~~~~~~~~~~~~~~~~~~~~~~
  1319. The maximum number of seconds :mod:`~celery.bin.beat` can sleep
  1320. between checking the schedule.
  1321. The default for this value is scheduler specific.
  1322. For the default celery beat scheduler the value is 300 (5 minutes),
  1323. but for e.g. the django-celery database scheduler it is 5 seconds
  1324. because the schedule may be changed externally, and so it must take
  1325. changes to the schedule into account.
  1326. Also when running celery beat embedded (:option:`-B`) on Jython as a thread
  1327. the max interval is overridden and set to 1 so that it's possible
  1328. to shut down in a timely manner.