configuration.rst 29 KB

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