configuration.rst 47 KB

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