configuration.rst 32 KB

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