configuration.rst 31 KB

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