configuration.rst 51 KB

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