configuration.rst 52 KB

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