configuration.rst 50 KB

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