configuration.rst 33 KB

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