configuration.rst 31 KB

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