configuration.rst 47 KB

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