configuration.rst 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  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. # List of modules to import when celery starts.
  18. CELERY_IMPORTS = ("myapp.tasks", )
  19. ## Result store settings.
  20. CELERY_RESULT_BACKEND = "database"
  21. CELERY_RESULT_DBURI = "sqlite:///mydatabase.db"
  22. ## Broker settings.
  23. BROKER_HOST = "localhost"
  24. BROKER_PORT = 5672
  25. BROKER_VHOST = "/"
  26. BROKER_USER = "guest"
  27. BROKER_PASSWORD = "guest"
  28. ## Worker settings
  29. ## If you're doing mostly I/O you can have more processes,
  30. ## but if mostly spending CPU, try to keep it close to the
  31. ## number of CPUs on your machine. If not set, the number of CPUs/cores
  32. ## available will be used.
  33. CELERYD_CONCURRENCY = 10
  34. # CELERYD_LOG_FILE = "celeryd.log"
  35. # CELERYD_LOG_LEVEL = "INFO"
  36. Configuration Directives
  37. ========================
  38. .. _conf-concurrency:
  39. Concurrency settings
  40. --------------------
  41. .. setting:: CELERYD_CONCURRENCY
  42. CELERYD_CONCURRENCY
  43. ~~~~~~~~~~~~~~~~~~~
  44. The number of concurrent worker processes/threads/green threads, executing
  45. tasks.
  46. Defaults to the number of available CPUs.
  47. .. setting:: CELERYD_PREFETCH_MULTIPLIER
  48. CELERYD_PREFETCH_MULTIPLIER
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. How many messages to prefetch at a time multiplied by the number of
  51. concurrent processes. The default is 4 (four messages for each
  52. process). The default setting is usually a good choice, however -- if you
  53. have very long running tasks waiting in the queue and you have to start the
  54. workers, note that the first worker to start will receive four times the
  55. number of messages initially. Thus the tasks may not be fairly distributed
  56. to the workers.
  57. .. _conf-result-backend:
  58. Task result backend settings
  59. ----------------------------
  60. .. setting:: CELERY_RESULT_BACKEND
  61. CELERY_RESULT_BACKEND
  62. ~~~~~~~~~~~~~~~~~~~~~
  63. :Deprecated aliases: ``CELERY_BACKEND``
  64. The backend used to store task results (tombstones).
  65. Disabled by default.
  66. Can be one of the following:
  67. * database
  68. Use a relational database supported by `SQLAlchemy`_.
  69. See :ref:`conf-database-result-backend`.
  70. * cache
  71. Use `memcached`_ to store the results.
  72. See :ref:`conf-cache-result-backend`.
  73. * mongodb
  74. Use `MongoDB`_ to store the results.
  75. See :ref:`conf-mongodb-result-backend`.
  76. * redis
  77. Use `Redis`_ to store the results.
  78. See :ref:`conf-redis-result-backend`.
  79. * tyrant
  80. Use `Tokyo Tyrant`_ to store the results.
  81. See :ref:`conf-tyrant-result-backend`.
  82. * amqp
  83. Send results back as AMQP messages
  84. See :ref:`conf-amqp-result-backend`.
  85. .. warning:
  86. While the AMQP result backend is very efficient, you must make sure
  87. you only receive the same result once. See :doc:`userguide/executing`).
  88. .. _`SQLAlchemy`: http://sqlalchemy.org
  89. .. _`memcached`: http://memcached.org
  90. .. _`MongoDB`: http://mongodb.org
  91. .. _`Redis`: http://code.google.com/p/redis/
  92. .. _`Tokyo Tyrant`: http://1978th.net/tokyotyrant/
  93. .. _conf-database-result-backend:
  94. Database backend settings
  95. -------------------------
  96. .. setting:: CELERY_RESULT_DBURI
  97. CELERY_RESULT_DBURI
  98. ~~~~~~~~~~~~~~~~~~~
  99. Please see `Supported Databases`_ for a table of supported databases.
  100. To use this backend you need to configure it with an
  101. `Connection String`_, some examples include:
  102. .. code-block:: python
  103. # sqlite (filename)
  104. CELERY_RESULT_DBURI = "sqlite:///celerydb.sqlite"
  105. # mysql
  106. CELERY_RESULT_DBURI = "mysql://scott:tiger@localhost/foo"
  107. # postgresql
  108. CELERY_RESULT_DBURI = "postgresql://scott:tiger@localhost/mydatabase"
  109. # oracle
  110. CELERY_RESULT_DBURI = "oracle://scott:tiger@127.0.0.1:1521/sidname"
  111. See `Connection String`_ for more information about connection
  112. strings.
  113. .. setting:: CELERY_RESULT_ENGINE_OPTIONS
  114. CELERY_RESULT_ENGINE_OPTIONS
  115. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  116. To specify additional SQLAlchemy database engine options you can use
  117. the :setting:`CELERY_RESULT_ENGINE_OPTIONS` setting::
  118. # echo enables verbose logging from SQLAlchemy.
  119. CELERY_RESULT_ENGINE_OPTIONS = {"echo": True}
  120. .. _`Supported Databases`:
  121. http://www.sqlalchemy.org/docs/core/engines.html#supported-databases
  122. .. _`Connection String`:
  123. http://www.sqlalchemy.org/docs/core/engines.html#database-urls
  124. Example configuration
  125. ~~~~~~~~~~~~~~~~~~~~~
  126. .. code-block:: python
  127. CELERY_RESULT_BACKEND = "database"
  128. CELERY_RESULT_DBURI = "mysql://user:password@host/dbname"
  129. .. _conf-amqp-result-backend:
  130. AMQP backend settings
  131. ---------------------
  132. .. setting:: CELERY_AMQP_TASK_RESULT_EXPIRES
  133. CELERY_AMQP_TASK_RESULT_EXPIRES
  134. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135. The time in seconds of which the task result queues should expire.
  136. .. note::
  137. AMQP result expiration requires RabbitMQ versions 2.1.0 and higher.
  138. .. setting:: CELERY_AMQP_TASK_RESULT_CONNECTION_MAX
  139. CELERY_AMQP_TASK_RESULT_CONNECTION_MAX
  140. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141. Maximum number of connections used by the AMQP result backend simultaneously.
  142. Default is 1 (a single connection per process).
  143. .. setting:: CELERY_RESULT_EXCHANGE
  144. CELERY_RESULT_EXCHANGE
  145. ~~~~~~~~~~~~~~~~~~~~~~
  146. Name of the exchange to publish results in. Default is `"celeryresults"`.
  147. .. setting:: CELERY_RESULT_EXCHANGE_TYPE
  148. CELERY_RESULT_EXCHANGE_TYPE
  149. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. The exchange type of the result exchange. Default is to use a `direct`
  151. exchange.
  152. .. setting:: CELERY_RESULT_SERIALIZER
  153. CELERY_RESULT_SERIALIZER
  154. ~~~~~~~~~~~~~~~~~~~~~~~~
  155. Result message serialization format. Default is `"pickle"`. See
  156. :ref:`executing-serializers`.
  157. .. setting:: CELERY_RESULT_PERSISTENT
  158. CELERY_RESULT_PERSISTENT
  159. ~~~~~~~~~~~~~~~~~~~~~~~~
  160. If set to :const:`True`, result messages will be persistent. This means the
  161. messages will not be lost after a broker restart. The default is for the
  162. results to be transient.
  163. Example configuration
  164. ~~~~~~~~~~~~~~~~~~~~~
  165. .. code-block:: python
  166. CELERY_RESULT_BACKEND = "amqp"
  167. CELERY_AMQP_TASK_RESULT_EXPIRES = 18000 # 5 hours.
  168. .. _conf-cache-result-backend:
  169. Cache backend settings
  170. ----------------------
  171. .. note::
  172. The cache backend supports the `pylibmc`_ and `python-memcached`
  173. libraries. The latter is used only if `pylibmc`_ is not installed.
  174. .. setting:: CELERY_CACHE_BACKEND
  175. CELERY_CACHE_BACKEND
  176. ~~~~~~~~~~~~~~~~~~~~
  177. Using a single memcached server:
  178. .. code-block:: python
  179. CELERY_CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
  180. Using multiple memcached servers:
  181. .. code-block:: python
  182. CELERY_RESULT_BACKEND = "cache"
  183. CELERY_CACHE_BACKEND = 'memcached://172.19.26.240:11211;172.19.26.242:11211/'
  184. .. setting:: CELERY_CACHE_BACKEND_OPTIONS
  185. The "dummy" backend stores the cache in memory only:
  186. CELERY_CACHE_BACKEND = "dummy"
  187. CELERY_CACHE_BACKEND_OPTIONS
  188. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  189. You can set pylibmc options using the :setting:`CELERY_CACHE_BACKEND_OPTIONS`
  190. setting:
  191. .. code-block:: python
  192. CELERY_CACHE_BACKEND_OPTIONS = {"binary": True,
  193. "behaviors": {"tcp_nodelay": True}}
  194. .. _`pylibmc`: http://sendapatch.se/projects/pylibmc/
  195. .. _conf-tyrant-result-backend:
  196. Tokyo Tyrant backend settings
  197. -----------------------------
  198. .. note::
  199. The Tokyo Tyrant backend requires the :mod:`pytyrant` library:
  200. http://pypi.python.org/pypi/pytyrant/
  201. This backend requires the following configuration directives to be set:
  202. .. setting:: TT_HOST
  203. TT_HOST
  204. ~~~~~~~
  205. Host name of the Tokyo Tyrant server.
  206. .. setting:: TT_PORT
  207. TT_PORT
  208. ~~~~~~~
  209. The port the Tokyo Tyrant server is listening to.
  210. Example configuration
  211. ~~~~~~~~~~~~~~~~~~~~~
  212. .. code-block:: python
  213. CELERY_RESULT_BACKEND = "tyrant"
  214. TT_HOST = "localhost"
  215. TT_PORT = 1978
  216. .. _conf-redis-result-backend:
  217. Redis backend settings
  218. ----------------------
  219. .. note::
  220. The Redis backend requires the :mod:`redis` library:
  221. http://pypi.python.org/pypi/redis/
  222. To install the redis package use `pip` or `easy_install`::
  223. $ pip install redis
  224. This backend requires the following configuration directives to be set.
  225. .. setting:: REDIS_HOST
  226. REDIS_HOST
  227. ~~~~~~~~~~
  228. Host name of the Redis database server. e.g. `"localhost"`.
  229. .. setting:: REDIS_PORT
  230. REDIS_PORT
  231. ~~~~~~~~~~
  232. Port to the Redis database server. e.g. `6379`.
  233. .. setting:: REDIS_DB
  234. REDIS_DB
  235. ~~~~~~~~
  236. Database number to use. Default is 0
  237. .. setting:: REDIS_PASSWORD
  238. REDIS_PASSWORD
  239. ~~~~~~~~~~~~~~
  240. Password used to connect to the database.
  241. Example configuration
  242. ~~~~~~~~~~~~~~~~~~~~~
  243. .. code-block:: python
  244. CELERY_RESULT_BACKEND = "redis"
  245. REDIS_HOST = "localhost"
  246. REDIS_PORT = 6379
  247. REDIS_DB = 0
  248. REDIS_CONNECT_RETRY = True
  249. .. _conf-mongodb-result-backend:
  250. MongoDB backend settings
  251. ------------------------
  252. .. note::
  253. The MongoDB backend requires the :mod:`pymongo` library:
  254. http://github.com/mongodb/mongo-python-driver/tree/master
  255. .. setting:: CELERY_MONGODB_BACKEND_SETTINGS
  256. CELERY_MONGODB_BACKEND_SETTINGS
  257. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  258. This is a dict supporting the following keys:
  259. * host
  260. Host name of the MongoDB server. Defaults to "localhost".
  261. * port
  262. The port the MongoDB server is listening to. Defaults to 27017.
  263. * user
  264. User name to authenticate to the MongoDB server as (optional).
  265. * password
  266. Password to authenticate to the MongoDB server (optional).
  267. * database
  268. The database name to connect to. Defaults to "celery".
  269. * taskmeta_collection
  270. The collection name to store task meta data.
  271. Defaults to "celery_taskmeta".
  272. .. _example-mongodb-result-config:
  273. Example configuration
  274. ~~~~~~~~~~~~~~~~~~~~~
  275. .. code-block:: python
  276. CELERY_RESULT_BACKEND = "mongodb"
  277. CELERY_MONGODB_BACKEND_SETTINGS = {
  278. "host": "192.168.1.100",
  279. "port": 30000,
  280. "database": "mydb",
  281. "taskmeta_collection": "my_taskmeta_collection",
  282. }
  283. .. _conf-messaging:
  284. Message Routing
  285. ---------------
  286. .. _conf-messaging-routing:
  287. .. setting:: CELERY_QUEUES
  288. CELERY_QUEUES
  289. ~~~~~~~~~~~~~
  290. The mapping of queues the worker consumes from. This is a dictionary
  291. of queue name/options. See :ref:`guide-routing` for more information.
  292. The default is a queue/exchange/binding key of `"celery"`, with
  293. exchange type `direct`.
  294. You don't have to care about this unless you want custom routing facilities.
  295. .. setting:: CELERY_ROUTES
  296. CELERY_ROUTES
  297. ~~~~~~~~~~~~~
  298. A list of routers, or a single router used to route tasks to queues.
  299. When deciding the final destination of a task the routers are consulted
  300. in order. See :ref:`routers` for more information.
  301. .. setting:: CELERY_CREATE_MISSING_QUEUES
  302. CELERY_CREATE_MISSING_QUEUES
  303. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  304. If enabled (default), any queues specified that is not defined in
  305. :setting:`CELERY_QUEUES` will be automatically created. See
  306. :ref:`routing-automatic`.
  307. .. setting:: CELERY_DEFAULT_QUEUE
  308. CELERY_DEFAULT_QUEUE
  309. ~~~~~~~~~~~~~~~~~~~~
  310. The queue used by default, if no custom queue is specified. This queue must
  311. be listed in :setting:`CELERY_QUEUES`. The default is: `celery`.
  312. .. seealso::
  313. :ref:`routing-changing-default-queue`
  314. .. setting:: CELERY_DEFAULT_EXCHANGE
  315. CELERY_DEFAULT_EXCHANGE
  316. ~~~~~~~~~~~~~~~~~~~~~~~
  317. Name of the default exchange to use when no custom exchange is
  318. specified. The default is: `celery`.
  319. .. setting:: CELERY_DEFAULT_EXCHANGE_TYPE
  320. CELERY_DEFAULT_EXCHANGE_TYPE
  321. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  322. Default exchange type used when no custom exchange is specified.
  323. The default is: `direct`.
  324. .. setting:: CELERY_DEFAULT_ROUTING_KEY
  325. CELERY_DEFAULT_ROUTING_KEY
  326. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  327. The default routing key used when sending tasks.
  328. The default is: `celery`.
  329. .. setting:: CELERY_DEFAULT_DELIVERY_MODE
  330. CELERY_DEFAULT_DELIVERY_MODE
  331. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  332. Can be `transient` or `persistent`. The default is to send
  333. persistent messages.
  334. .. _conf-broker-connection:
  335. Broker Settings
  336. ---------------
  337. .. setting:: BROKER_TRANSPORT
  338. BROKER_TRANSPORT
  339. ~~~~~~~~~~~~~~~~
  340. :Aliases: ``BROKER_BACKEND``
  341. :Deprecated aliases: ``CARROT_BACKEND``
  342. The Kombu transport to use. Default is ``amqplib``.
  343. You can use a custom transport class name, or select one of the
  344. built-in transports: ``amqplib``, ``pika``, ``redis``, ``beanstalk``,
  345. ``sqlalchemy``, ``django``, ``mongodb``, ``couchdb``.
  346. .. setting:: BROKER_HOST
  347. BROKER_HOST
  348. ~~~~~~~~~~~
  349. Hostname of the broker.
  350. .. setting:: BROKER_PORT
  351. BROKER_PORT
  352. ~~~~~~~~~~~
  353. Custom port of the broker. Default is to use the default port for the
  354. selected backend.
  355. .. setting:: BROKER_USER
  356. BROKER_USER
  357. ~~~~~~~~~~~
  358. Username to connect as.
  359. .. setting:: BROKER_PASSWORD
  360. BROKER_PASSWORD
  361. ~~~~~~~~~~~~~~~
  362. Password to connect with.
  363. .. setting:: BROKER_VHOST
  364. BROKER_VHOST
  365. ~~~~~~~~~~~~
  366. Virtual host. Default is `"/"`.
  367. .. setting:: BROKER_USE_SSL
  368. BROKER_USE_SSL
  369. ~~~~~~~~~~~~~~
  370. Use SSL to connect to the broker. Off by default. This may not be supported
  371. by all transports.
  372. .. setting:: BROKER_POOL_LIMIT
  373. BROKER_POOL_LIMIT
  374. ~~~~~~~~~~~~~~~~~
  375. The maximum number of connections that can be open in the connection pool.
  376. A good default value could be 10, or more if you're using eventlet/gevent
  377. or lots of threads.
  378. If set to :const:`None` or 0 the connection pool will be disabled and
  379. connections will be established and closed for every use.
  380. **Disabled by default.**
  381. .. setting:: BROKER_CONNECTION_TIMEOUT
  382. BROKER_CONNECTION_TIMEOUT
  383. ~~~~~~~~~~~~~~~~~~~~~~~~~
  384. The default timeout in seconds before we give up establishing a connection
  385. to the AMQP server. Default is 4 seconds.
  386. .. setting:: BROKER_CONNECTION_RETRY
  387. BROKER_CONNECTION_RETRY
  388. ~~~~~~~~~~~~~~~~~~~~~~~
  389. Automatically try to re-establish the connection to the AMQP broker if lost.
  390. The time between retries is increased for each retry, and is
  391. not exhausted before :setting:`BROKER_CONNECTION_MAX_RETRIES` is
  392. exceeded.
  393. This behavior is on by default.
  394. .. setting:: BROKER_CONNECTION_MAX_RETRIES
  395. BROKER_CONNECTION_MAX_RETRIES
  396. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  397. Maximum number of retries before we give up re-establishing a connection
  398. to the AMQP broker.
  399. If this is set to :const:`0` or :const:`None`, we will retry forever.
  400. Default is 100 retries.
  401. .. setting:: BROKER_TRANSPORT_OPTIONS
  402. BROKER_TRANSPORT_OPTIONS
  403. ~~~~~~~~~~~~~~~~~~~~~~~~
  404. A dict of additional options passed to the underlying transport.
  405. See your transport user manual for supported options (if any).
  406. .. _conf-task-execution:
  407. Task execution settings
  408. -----------------------
  409. .. setting:: CELERY_ALWAYS_EAGER
  410. CELERY_ALWAYS_EAGER
  411. ~~~~~~~~~~~~~~~~~~~
  412. If this is :const:`True`, all tasks will be executed locally by blocking until
  413. the task returns. ``apply_async()`` and ``Task.delay()`` will return
  414. an :class:`~celery.result.EagerResult` instance, which emulates the API
  415. and behavior of :class:`~celery.result.AsyncResult`, except the result
  416. is already evaluated.
  417. That is, tasks will be executed locally instead of being sent to
  418. the queue.
  419. .. setting:: CELERY_EAGER_PROPAGATES_EXCEPTIONS
  420. CELERY_EAGER_PROPAGATES_EXCEPTIONS
  421. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  422. If this is :const:`True`, eagerly executed tasks (applied by `task.apply()`,
  423. or when the :setting:`CELERY_ALWAYS_EAGER` setting is enabled), will
  424. propagate exceptions.
  425. It's the same as always running ``apply()`` with ``throw=True``.
  426. .. setting:: CELERY_IGNORE_RESULT
  427. CELERY_IGNORE_RESULT
  428. ~~~~~~~~~~~~~~~~~~~~
  429. Whether to store the task return values or not (tombstones).
  430. If you still want to store errors, just not successful return values,
  431. you can set :setting:`CELERY_STORE_ERRORS_EVEN_IF_IGNORED`.
  432. .. setting:: CELERY_MESSAGE_COMPRESSION
  433. CELERY_MESSAGE_COMPRESSION
  434. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  435. Default compression used for task messages.
  436. Can be ``"gzip"``, ``"bzip2"`` (if available), or any custom
  437. compression schemes registered in the Kombu compression registry.
  438. The default is to send uncompressed messages.
  439. .. setting:: CELERY_TASK_RESULT_EXPIRES
  440. CELERY_TASK_RESULT_EXPIRES
  441. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  442. Time (in seconds, or a :class:`~datetime.timedelta` object) for when after
  443. stored task tombstones will be deleted.
  444. A built-in periodic task will delete the results after this time
  445. (:class:`celery.task.backend_cleanup`).
  446. .. note::
  447. For the moment this only works with the database, cache, redis and MongoDB
  448. backends. For the AMQP backend see
  449. :setting:`CELERY_AMQP_TASK_RESULT_EXPIRES`.
  450. When using the database or MongoDB backends, `celerybeat` must be
  451. running for the results to be expired.
  452. .. setting:: CELERY_MAX_CACHED_RESULTS
  453. CELERY_MAX_CACHED_RESULTS
  454. ~~~~~~~~~~~~~~~~~~~~~~~~~
  455. Result backends caches ready results used by the client.
  456. This is the total number of results to cache before older results are evicted.
  457. The default is 5000.
  458. .. setting:: CELERY_TRACK_STARTED
  459. CELERY_TRACK_STARTED
  460. ~~~~~~~~~~~~~~~~~~~~
  461. If :const:`True` the task will report its status as "started" when the
  462. task is executed by a worker. The default value is :const:`False` as
  463. the normal behaviour is to not report that level of granularity. Tasks
  464. are either pending, finished, or waiting to be retried. Having a "started"
  465. state can be useful for when there are long running tasks and there is a
  466. need to report which task is currently running.
  467. .. setting:: CELERY_TASK_SERIALIZER
  468. CELERY_TASK_SERIALIZER
  469. ~~~~~~~~~~~~~~~~~~~~~~
  470. A string identifying the default serialization method to use. Can be
  471. `pickle` (default), `json`, `yaml`, `msgpack` or any custom serialization
  472. methods that have been registered with :mod:`kombu.serialization.registry`.
  473. .. seealso::
  474. :ref:`executing-serializers`.
  475. .. setting:: CELERY_TASK_PUBLISH_RETRY
  476. CELERY_TASK_PUBLISH_RETRY
  477. ~~~~~~~~~~~~~~~~~~~~~~~~~
  478. Decides if publishing task messages will be retried in the case
  479. of connection loss or other connection errors.
  480. See also :setting:`CELERY_TASK_PUBLISH_RETRY_POLICY`.
  481. Disabled by default.
  482. .. setting:: CELERY_TASK_PUBLISH_RETRY_POLICY
  483. Defines the default policy when retrying publishing a task message in
  484. the case of connection loss or other connection errors.
  485. This is a mapping that must contain the following keys:
  486. * `max_retries`
  487. Maximum number of retries before giving up, in this case the
  488. exception that caused the retry to fail will be raised.
  489. A value of 0 or :const:`None` means it will retry forever.
  490. The default is to retry 3 times.
  491. * `interval_start`
  492. Defines the number of seconds (float or integer) to wait between
  493. retries. Default is 0, which means the first retry will be
  494. instantaneous.
  495. * `interval_step`
  496. On each consecutive retry this number will be added to the retry
  497. delay (float or integer). Default is 0.2.
  498. * `interval_max`
  499. Maximum number of seconds (float or integer) to wait between
  500. retries. Default is 0.2.
  501. With the default policy of::
  502. {"max_retries": 3,
  503. "interval_start": 0,
  504. "interval_step": 0.2,
  505. "interval_max": 0.2}
  506. the maximum time spent retrying will be 0.4 seconds. It is set relatively
  507. short by default because a connection failure could lead to a retry pile effect
  508. if the broker connection is down: e.g. many web server processes waiting
  509. to retry blocking other incoming requests.
  510. CELERY_TASK_PUBLISH_RETRY_POLICY
  511. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  512. .. setting:: CELERY_DEFAULT_RATE_LIMIT
  513. CELERY_DEFAULT_RATE_LIMIT
  514. ~~~~~~~~~~~~~~~~~~~~~~~~~
  515. The global default rate limit for tasks.
  516. This value is used for tasks that does not have a custom rate limit
  517. The default is no rate limit.
  518. .. setting:: CELERY_DISABLE_RATE_LIMITS
  519. CELERY_DISABLE_RATE_LIMITS
  520. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  521. Disable all rate limits, even if tasks has explicit rate limits set.
  522. .. setting:: CELERY_ACKS_LATE
  523. CELERY_ACKS_LATE
  524. ~~~~~~~~~~~~~~~~
  525. Late ack means the task messages will be acknowledged **after** the task
  526. has been executed, not *just before*, which is the default behavior.
  527. .. seealso::
  528. FAQ: :ref:`faq-acks_late-vs-retry`.
  529. .. _conf-celeryd:
  530. Worker: celeryd
  531. ---------------
  532. .. setting:: CELERY_IMPORTS
  533. CELERY_IMPORTS
  534. ~~~~~~~~~~~~~~
  535. A sequence of modules to import when the celery daemon starts.
  536. This is used to specify the task modules to import, but also
  537. to import signal handlers and additional remote control commands, etc.
  538. .. setting:: CELERYD_MAX_TASKS_PER_CHILD
  539. CELERYD_MAX_TASKS_PER_CHILD
  540. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  541. Maximum number of tasks a pool worker process can execute before
  542. it's replaced with a new one. Default is no limit.
  543. .. setting:: CELERYD_TASK_TIME_LIMIT
  544. CELERYD_TASK_TIME_LIMIT
  545. ~~~~~~~~~~~~~~~~~~~~~~~
  546. Task hard time limit in seconds. The worker processing the task will
  547. be killed and replaced with a new one when this is exceeded.
  548. .. setting:: CELERYD_TASK_SOFT_TIME_LIMIT
  549. CELERYD_TASK_SOFT_TIME_LIMIT
  550. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  551. Task soft time limit in seconds.
  552. The :exc:`~celery.exceptions.SoftTimeLimitExceeded` exception will be
  553. raised when this is exceeded. The task can catch this to
  554. e.g. clean up before the hard time limit comes.
  555. Example:
  556. .. code-block:: python
  557. from celery.task import task
  558. from celery.exceptions import SoftTimeLimitExceeded
  559. @task()
  560. def mytask():
  561. try:
  562. return do_work()
  563. except SoftTimeLimitExceeded:
  564. cleanup_in_a_hurry()
  565. .. setting:: CELERY_STORE_ERRORS_EVEN_IF_IGNORED
  566. CELERY_STORE_ERRORS_EVEN_IF_IGNORED
  567. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  568. If set, the worker stores all task errors in the result store even if
  569. :attr:`Task.ignore_result <celery.task.base.Task.ignore_result>` is on.
  570. .. setting:: CELERYD_STATE_DB
  571. CELERYD_STATE_DB
  572. ~~~~~~~~~~~~~~~~
  573. Name of the file used to stores persistent worker state (like revoked tasks).
  574. Can be a relative or absolute path, but be aware that the suffix `.db`
  575. may be appended to the file name (depending on Python version).
  576. Can also be set via the :option:`--statedb` argument to
  577. :mod:`~celery.bin.celeryd`.
  578. Not enabled by default.
  579. .. setting:: CELERYD_ETA_SCHEDULER_PRECISION
  580. CELERYD_ETA_SCHEDULER_PRECISION
  581. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  582. Set the maximum time in seconds that the ETA scheduler can sleep between
  583. rechecking the schedule. Default is 1 second.
  584. Setting this value to 1 second means the schedulers precision will
  585. be 1 second. If you need near millisecond precision you can set this to 0.1.
  586. .. _conf-error-mails:
  587. Error E-Mails
  588. -------------
  589. .. setting:: CELERY_SEND_TASK_ERROR_EMAILS
  590. CELERY_SEND_TASK_ERROR_EMAILS
  591. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  592. The default value for the `Task.send_error_emails` attribute, which if
  593. set to :const:`True` means errors occurring during task execution will be
  594. sent to :setting:`ADMINS` by email.
  595. .. setting:: CELERY_TASK_ERROR_WHITELIST
  596. CELERY_TASK_ERROR_WHITELIST
  597. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  598. A white list of exceptions to send error emails for.
  599. .. setting:: ADMINS
  600. ADMINS
  601. ~~~~~~
  602. List of `(name, email_address)` tuples for the administrators that should
  603. receive error emails.
  604. .. setting:: SERVER_EMAIL
  605. SERVER_EMAIL
  606. ~~~~~~~~~~~~
  607. The email address this worker sends emails from.
  608. Default is celery@localhost.
  609. .. setting:: EMAIL_HOST
  610. EMAIL_HOST
  611. ~~~~~~~~~~
  612. The mail server to use. Default is `"localhost"`.
  613. .. setting:: EMAIL_HOST_USER
  614. EMAIL_HOST_USER
  615. ~~~~~~~~~~~~~~~
  616. User name (if required) to log on to the mail server with.
  617. .. setting:: EMAIL_HOST_PASSWORD
  618. EMAIL_HOST_PASSWORD
  619. ~~~~~~~~~~~~~~~~~~~
  620. Password (if required) to log on to the mail server with.
  621. .. setting:: EMAIL_PORT
  622. EMAIL_PORT
  623. ~~~~~~~~~~
  624. The port the mail server is listening on. Default is `25`.
  625. .. setting:: EMAIL_TIMEOUT
  626. EMAIL_TIMEOUT
  627. ~~~~~~~~~~~~~
  628. Timeout in seconds for when we give up trying to connect
  629. to the SMTP server when sending emails.
  630. The default is 2 seconds.
  631. .. _conf-example-error-mail-config:
  632. Example E-Mail configuration
  633. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  634. This configuration enables the sending of error emails to
  635. george@vandelay.com and kramer@vandelay.com:
  636. .. code-block:: python
  637. # Enables error emails.
  638. CELERY_SEND_TASK_ERROR_EMAILS = True
  639. # Name and email addresses of recipients
  640. ADMINS = (
  641. ("George Costanza", "george@vandelay.com"),
  642. ("Cosmo Kramer", "kosmo@vandelay.com"),
  643. )
  644. # Email address used as sender (From field).
  645. SERVER_EMAIL = "no-reply@vandelay.com"
  646. # Mailserver configuration
  647. EMAIL_HOST = "mail.vandelay.com"
  648. EMAIL_PORT = 25
  649. # EMAIL_HOST_USER = "servers"
  650. # EMAIL_HOST_PASSWORD = "s3cr3t"
  651. .. _conf-events:
  652. Events
  653. ------
  654. .. setting:: CELERY_SEND_EVENTS
  655. CELERY_SEND_EVENTS
  656. ~~~~~~~~~~~~~~~~~~
  657. Send events so the worker can be monitored by tools like `celerymon`.
  658. .. setting:: CELERY_SEND_TASK_SENT_EVENT
  659. CELERY_SEND_TASK_SENT_EVENT
  660. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  661. If enabled, a `task-sent` event will be sent for every task so tasks can be
  662. tracked before they are consumed by a worker.
  663. Disabled by default.
  664. .. setting:: CELERY_EVENT_SERIALIZER
  665. CELERY_EVENT_SERIALIZER
  666. ~~~~~~~~~~~~~~~~~~~~~~~
  667. Message serialization format used when sending event messages.
  668. Default is `"json"`. See :ref:`executing-serializers`.
  669. .. _conf-broadcast:
  670. Broadcast Commands
  671. ------------------
  672. .. setting:: CELERY_BROADCAST_QUEUE
  673. CELERY_BROADCAST_QUEUE
  674. ~~~~~~~~~~~~~~~~~~~~~~
  675. Name prefix for the queue used when listening for broadcast messages.
  676. The workers host name will be appended to the prefix to create the final
  677. queue name.
  678. Default is `"celeryctl"`.
  679. .. setting:: CELERY_BROADCAST_EXCHANGE
  680. CELERY_BROADCAST_EXCHANGE
  681. ~~~~~~~~~~~~~~~~~~~~~~~~~
  682. Name of the exchange used for broadcast messages.
  683. Default is `"celeryctl"`.
  684. .. setting:: CELERY_BROADCAST_EXCHANGE_TYPE
  685. CELERY_BROADCAST_EXCHANGE_TYPE
  686. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  687. Exchange type used for broadcast messages. Default is `"fanout"`.
  688. .. _conf-logging:
  689. Logging
  690. -------
  691. .. setting:: CELERYD_HIJACK_ROOT_LOGGER
  692. CELERYD_HIJACK_ROOT_LOGGER
  693. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  694. By default any previously configured logging options will be reset,
  695. because the Celery apps "hijacks" the root logger.
  696. If you want to customize your own logging then you can disable
  697. this behavior.
  698. .. note::
  699. Logging can also be customized by connecting to the
  700. :signal:`celery.signals.setup_logging` signal.
  701. .. setting:: CELERYD_LOG_FILE
  702. CELERYD_LOG_FILE
  703. ~~~~~~~~~~~~~~~~
  704. The default file name the worker daemon logs messages to. Can be overridden
  705. using the :option:`--logfile` option to :mod:`~celery.bin.celeryd`.
  706. The default is :const:`None` (`stderr`)
  707. .. setting:: CELERYD_LOG_LEVEL
  708. CELERYD_LOG_LEVEL
  709. ~~~~~~~~~~~~~~~~~
  710. Worker log level, can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
  711. :const:`ERROR` or :const:`CRITICAL`.
  712. Can also be set via the :option:`--loglevel` argument to
  713. :mod:`~celery.bin.celeryd`.
  714. See the :mod:`logging` module for more information.
  715. .. setting:: CELERYD_LOG_COLOR
  716. CELERYD_LOG_COLOR
  717. ~~~~~~~~~~~~~~~~~
  718. Enables/disables colors in logging output by the Celery apps.
  719. By default colors are enabled if
  720. 1) the app is logging to a real terminal, and not a file.
  721. 2) the app is not running on Windows.
  722. .. setting:: CELERYD_LOG_FORMAT
  723. CELERYD_LOG_FORMAT
  724. ~~~~~~~~~~~~~~~~~~
  725. The format to use for log messages.
  726. Default is `[%(asctime)s: %(levelname)s/%(processName)s] %(message)s`
  727. See the Python :mod:`logging` module for more information about log
  728. formats.
  729. .. setting:: CELERYD_TASK_LOG_FORMAT
  730. CELERYD_TASK_LOG_FORMAT
  731. ~~~~~~~~~~~~~~~~~~~~~~~
  732. The format to use for log messages logged in tasks. Can be overridden using
  733. the :option:`--loglevel` option to :mod:`~celery.bin.celeryd`.
  734. Default is::
  735. [%(asctime)s: %(levelname)s/%(processName)s]
  736. [%(task_name)s(%(task_id)s)] %(message)s
  737. See the Python :mod:`logging` module for more information about log
  738. formats.
  739. .. setting:: CELERY_REDIRECT_STDOUTS
  740. CELERY_REDIRECT_STDOUTS
  741. ~~~~~~~~~~~~~~~~~~~~~~~
  742. If enabled `stdout` and `stderr` will be redirected
  743. to the current logger.
  744. Enabled by default.
  745. Used by :program:`celeryd` and :program:`celerybeat`.
  746. .. setting:: CELERY_REDIRECT_STDOUTS_LEVEL
  747. CELERY_REDIRECT_STDOUTS_LEVEL
  748. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  749. The log level output to `stdout` and `stderr` is logged as.
  750. Can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
  751. :const:`ERROR` or :const:`CRITICAL`.
  752. Default is :const:`WARNING`.
  753. .. _conf-custom-components:
  754. Custom Component Classes (advanced)
  755. -----------------------------------
  756. .. setting:: CELERYD_POOL
  757. CELERYD_POOL
  758. ~~~~~~~~~~~~
  759. Name of the pool class used by the worker.
  760. You can use a custom pool class name, or select one of
  761. the built-in aliases: ``processes``, ``eventlet``, ``gevent``.
  762. Default is ``processes``.
  763. .. setting:: CELERYD_AUTOSCALER
  764. CELERYD_AUTOSCALER
  765. ~~~~~~~~~~~~~~~~~~
  766. Name of the autoscaler class to use.
  767. Default is ``"celery.worker.autoscale.Autoscaler"``.
  768. .. setting:: CELERYD_CONSUMER
  769. CELERYD_CONSUMER
  770. ~~~~~~~~~~~~~~~~
  771. Name of the consumer class used by the worker.
  772. Default is :class:`celery.worker.consumer.Consumer`
  773. .. setting:: CELERYD_MEDIATOR
  774. CELERYD_MEDIATOR
  775. ~~~~~~~~~~~~~~~~
  776. Name of the mediator class used by the worker.
  777. Default is :class:`celery.worker.controllers.Mediator`.
  778. .. setting:: CELERYD_ETA_SCHEDULER
  779. CELERYD_ETA_SCHEDULER
  780. ~~~~~~~~~~~~~~~~~~~~~
  781. Name of the ETA scheduler class used by the worker.
  782. Default is :class:`celery.utils.timer2.Timer`, or one overrided
  783. by the pool implementation.
  784. .. _conf-celerybeat:
  785. Periodic Task Server: celerybeat
  786. --------------------------------
  787. .. setting:: CELERYBEAT_SCHEDULE
  788. CELERYBEAT_SCHEDULE
  789. ~~~~~~~~~~~~~~~~~~~
  790. The periodic task schedule used by :mod:`~celery.bin.celerybeat`.
  791. See :ref:`beat-entries`.
  792. .. setting:: CELERYBEAT_SCHEDULER
  793. CELERYBEAT_SCHEDULER
  794. ~~~~~~~~~~~~~~~~~~~~
  795. The default scheduler class. Default is
  796. `"celery.beat.PersistentScheduler"`.
  797. Can also be set via the :option:`-S` argument to
  798. :mod:`~celery.bin.celerybeat`.
  799. .. setting:: CELERYBEAT_SCHEDULE_FILENAME
  800. CELERYBEAT_SCHEDULE_FILENAME
  801. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  802. Name of the file used by `PersistentScheduler` to store the last run times
  803. of periodic tasks. Can be a relative or absolute path, but be aware that the
  804. suffix `.db` may be appended to the file name (depending on Python version).
  805. Can also be set via the :option:`--schedule` argument to
  806. :mod:`~celery.bin.celerybeat`.
  807. .. setting:: CELERYBEAT_MAX_LOOP_INTERVAL
  808. CELERYBEAT_MAX_LOOP_INTERVAL
  809. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  810. The maximum number of seconds :mod:`~celery.bin.celerybeat` can sleep
  811. between checking the schedule. Default is 300 seconds (5 minutes).
  812. .. setting:: CELERYBEAT_LOG_FILE
  813. CELERYBEAT_LOG_FILE
  814. ~~~~~~~~~~~~~~~~~~~
  815. The default file name to log messages to. Can be overridden using
  816. the `--logfile` option to :mod:`~celery.bin.celerybeat`.
  817. The default is :const:`None` (`stderr`).
  818. .. setting:: CELERYBEAT_LOG_LEVEL
  819. CELERYBEAT_LOG_LEVEL
  820. ~~~~~~~~~~~~~~~~~~~~
  821. Logging level. Can be any of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
  822. :const:`ERROR`, or :const:`CRITICAL`.
  823. Can also be set via the :option:`--loglevel` argument to
  824. :mod:`~celery.bin.celerybeat`.
  825. See the :mod:`logging` module for more information.
  826. .. _conf-celerymon:
  827. Monitor Server: celerymon
  828. -------------------------
  829. .. setting:: CELERYMON_LOG_FILE
  830. CELERYMON_LOG_FILE
  831. ~~~~~~~~~~~~~~~~~~
  832. The default file name to log messages to. Can be overridden using
  833. the :option:`--logfile` argument to `celerymon`.
  834. The default is :const:`None` (`stderr`)
  835. .. setting:: CELERYMON_LOG_LEVEL
  836. CELERYMON_LOG_LEVEL
  837. ~~~~~~~~~~~~~~~~~~~
  838. Logging level. Can be any of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
  839. :const:`ERROR`, or :const:`CRITICAL`.
  840. See the :mod:`logging` module for more information.
  841. .. setting:: CELERYMON_LOG_FORMAT
  842. CELERYMON_LOG_FORMAT
  843. ~~~~~~~~~~~~~~~~~~~~
  844. The format to use for log messages.
  845. Default is `[%(asctime)s: %(levelname)s/%(processName)s] %(message)s`
  846. See the Python :mod:`logging` module for more information about log
  847. formats.