configuration.rst 47 KB

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