configuration.rst 33 KB

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