configuration.rst 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  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. ## Broker settings.
  18. broker_url = 'amqp://guest:guest@localhost:5672//'
  19. # List of modules to import when celery starts.
  20. imports = ('myapp.tasks',)
  21. ## Using the database to store task state and results.
  22. result_backend = 'db+sqlite:///results.db'
  23. task_annotations = {'tasks.add': {'rate_limit': '10/s'}}
  24. .. _conf-old-settings-map:
  25. New lowercase settings
  26. ======================
  27. Version 4.0 introduced new lower case settings and setting organization.
  28. The major difference between previous versions, apart from the lower case
  29. names, are the renaming of some prefixes, like ``celerybeat_`` to ``beat_``,
  30. ``celeryd_`` to ``worker_``, and most of the top level ``celery_`` settings
  31. have been moved into a new ``task_`` prefix.
  32. Celery will still be able to read old configuration files, so there is no
  33. rush in moving to the new settings format.
  34. ===================================== ==============================================
  35. **Setting name** **Replace with**
  36. ===================================== ==============================================
  37. ``CELERY_ACCEPT_CONTENT`` :setting:`accept_content`
  38. ``CELERY_ENABLE_UTC`` :setting:`enable_utc`
  39. ``CELERY_IMPORTS`` :setting:`imports`
  40. ``CELERY_INCLUDE`` :setting:`include`
  41. ``CELERY_TIMEZONE`` :setting:`timezone`
  42. ``CELERYBEAT_MAX_LOOP_INTERVAL`` :setting:`beat_max_loop_interval`
  43. ``CELERYBEAT_SCHEDULE`` :setting:`beat_schedule`
  44. ``CELERYBEAT_SCHEDULER`` :setting:`beat_scheduler`
  45. ``CELERYBEAT_SCHEDULE_FILENAME`` :setting:`beat_schedule_filename`
  46. ``CELERYBEAT_SYNC_EVERY`` :setting:`beat_sync_every`
  47. ``BROKER_URL`` :setting:`broker_url`
  48. ``BROKER_TRANSPORT`` :setting:`broker_transport`
  49. ``BROKER_TRANSPORT_OPTIONS`` :setting:`broker_transport_options`
  50. ``BROKER_CONNECTION_TIMEOUT`` :setting:`broker_connection_timeout`
  51. ``BROKER_CONNECTION_RETRY`` :setting:`broker_connection_retry`
  52. ``BROKER_CONNECTION_MAX_RETRIES`` :setting:`broker_connection_max_retries`
  53. ``BROKER_FAILOVER_STRATEGY`` :setting:`broker_failover_strategy`
  54. ``BROKER_HEARTBEAT`` :setting:`broker_heartbeat`
  55. ``BROKER_LOGIN_METHOD`` :setting:`broker_login_method`
  56. ``BROKER_POOL_LIMIT`` :setting:`broker_pool_limit`
  57. ``BROKER_USE_SSL`` :setting:`broker_use_ssl`
  58. ``CELERY_CACHE_BACKEND`` :setting:`cache_backend`
  59. ``CELERY_CACHE_BACKEND_OPTIONS`` :setting:`cache_backend_options`
  60. ``CASSANDRA_COLUMN_FAMILY`` :setting:`cassandra_table`
  61. ``CASSANDRA_ENTRY_TTL`` :setting:`cassandra_entry_ttl`
  62. ``CASSANDRA_KEYSPACE`` :setting:`cassandra_keyspace`
  63. ``CASSANDRA_PORT`` :setting:`cassandra_port`
  64. ``CASSANDRA_READ_CONSISTENCY`` :setting:`cassandra_read_consistency`
  65. ``CASSANDRA_SERVERS`` :setting:`cassandra_servers`
  66. ``CASSANDRA_WRITE_CONSISTENCY`` :setting:`cassandra_write_consistency`
  67. ``CELERY_COUCHBASE_BACKEND_SETTINGS`` :setting:`couchbase_backend_settings`
  68. ``CELERY_MONGODB_BACKEND_SETTINGS`` :setting:`mongodb_backend_settings`
  69. ``CELERY_EVENT_QUEUE_EXPIRES`` :setting:`event_queue_expires`
  70. ``CELERY_EVENT_QUEUE_TTL`` :setting:`event_queue_ttl`
  71. ``CELERY_EVENT_QUEUE_PREFIX`` :setting:`event_queue_prefix`
  72. ``CELERY_EVENT_SERIALIZER`` :setting:`event_serializer`
  73. ``CELERY_REDIS_DB`` :setting:`redis_db`
  74. ``CELERY_REDIS_HOST`` :setting:`redis_host`
  75. ``CELERY_REDIS_MAX_CONNECTIONS`` :setting:`redis_max_connections`
  76. ``CELERY_REDIS_PASSWORD`` :setting:`redis_password`
  77. ``CELERY_REDIS_PORT`` :setting:`redis_port`
  78. ``CELERY_RESULT_BACKEND`` :setting:`result_backend`
  79. ``CELERY_MAX_CACHED_RESULTS`` :setting:`result_cache_max`
  80. ``CELERY_MESSAGE_COMPRESSION`` :setting:`result_compression`
  81. ``CELERY_RESULT_EXCHANGE`` :setting:`result_exchange`
  82. ``CELERY_RESULT_EXCHANGE_TYPE`` :setting:`result_exchange_type`
  83. ``CELERY_TASK_RESULT_EXPIRES`` :setting:`result_expires`
  84. ``CELERY_RESULT_PERSISTENT`` :setting:`result_persistent`
  85. ``CELERY_RESULT_SERIALIZER`` :setting:`result_serializer`
  86. ``CELERY_RESULT_DBURI`` :setting:`sqlalchemy_dburi`
  87. ``CELERY_RESULT_ENGINE_OPTIONS`` :setting:`sqlalchemy_engine_options`
  88. ``-*-_DB_SHORT_LIVED_SESSIONS`` :setting:`sqlalchemy_short_lived_sessions`
  89. ``CELERY_RESULT_DB_TABLE_NAMES`` :setting:`sqlalchemy_db_names`
  90. ``CELERY_SECURITY_CERTIFICATE`` :setting:`security_certificate`
  91. ``CELERY_SECURITY_CERT_STORE`` :setting:`security_cert_store`
  92. ``CELERY_SECURITY_KEY`` :setting:`security_key`
  93. ``CELERY_ACKS_LATE`` :setting:`task_acks_late`
  94. ``CELERY_ALWAYS_EAGER`` :setting:`task_always_eager`
  95. ``CELERY_ANNOTATIONS`` :setting:`task_annotations`
  96. ``CELERY_MESSAGE_COMPRESSION`` :setting:`task_compression`
  97. ``CELERY_CREATE_MISSING_QUEUES`` :setting:`task_create_missing_queues`
  98. ``CELERY_DEFAULT_DELIVERY_MODE`` :setting:`task_default_delivery_mode`
  99. ``CELERY_DEFAULT_EXCHANGE`` :setting:`task_default_exchange`
  100. ``CELERY_DEFAULT_EXCHANGE_TYPE`` :setting:`task_default_exchange_type`
  101. ``CELERY_DEFAULT_QUEUE`` :setting:`task_default_queue`
  102. ``CELERY_DEFAULT_RATE_LIMIT`` :setting:`task_default_rate_limit`
  103. ``CELERY_DEFAULT_ROUTING_KEY`` :setting:`task_default_routing_key`
  104. ``-'-_EAGER_PROPAGATES_EXCEPTIONS`` :setting:`task_eager_propagates`
  105. ``CELERY_IGNORE_RESULT`` :setting:`task_ignore_result`
  106. ``CELERY_TASK_PUBLISH_RETRY`` :setting:`task_publish_retry`
  107. ``CELERY_TASK_PUBLISH_RETRY_POLICY`` :setting:`task_publish_retry_policy`
  108. ``CELERY_QUEUES`` :setting:`task_queues`
  109. ``CELERY_ROUTES`` :setting:`task_routes`
  110. ``CELERY_SEND_TASK_SENT_EVENT`` :setting:`task_send_sent_event`
  111. ``CELERY_TASK_SERIALIZER`` :setting:`task_serializer`
  112. ``CELERYD_TASK_SOFT_TIME_LIMIT`` :setting:`task_soft_time_limit`
  113. ``CELERYD_TASK_TIME_LIMIT`` :setting:`task_time_limit`
  114. ``CELERY_TRACK_STARTED`` :setting:`task_track_started`
  115. ``CELERYD_AGENT`` :setting:`worker_agent`
  116. ``CELERYD_CONCURRENCY`` :setting:`worker_concurrency`
  117. ``CELERYD_CONSUMER`` :setting:`worker_consumer`
  118. ``CELERY_WORKER_DIRECT`` :setting:`worker_direct`
  119. ``CELERY_DISABLE_RATE_LIMITS`` :setting:`worker_disable_rate_limits`
  120. ``CELERY_ENABLE_REMOTE_CONTROL`` :setting:`worker_enable_remote_control`
  121. ``CELERYD_HIJACK_ROOT_LOGGER`` :setting:`worker_hijack_root_logger`
  122. ``CELERYD_LOG_COLOR`` :setting:`worker_log_color`
  123. ``CELERYD_LOG_FORMAT`` :setting:`worker_log_format`
  124. ``CELERYD_WORKER_LOST_WAIT`` :setting:`worker_lost_wait`
  125. ``CELERYD_MAX_TASKS_PER_CHILD`` :setting:`worker_max_tasks_per_child`
  126. ``CELERYD_POOL`` :setting:`worker_pool`
  127. ``CELERYD_POOL_PUTLOCKS`` :setting:`worker_pool_putlocks`
  128. ``CELERYD_POOL_RESTARTS`` :setting:`worker_pool_restarts`
  129. ``CELERYD_PREFETCH_MULTIPLIER`` :setting:`worker_prefetch_multiplier`
  130. ``CELERYD_REDIRECT_STDOUTS`` :setting:`worker_redirect_stdouts`
  131. ``CELERYD_REDIRECT_STDOUTS_LEVEL`` :setting:`worker_redirect_stdouts_level`
  132. ``CELERYD_SEND_EVENTS`` :setting:`worker_send_task_events`
  133. ``CELERYD_STATE_DB`` :setting:`worker_state_db`
  134. ``CELERYD_TASK_LOG_FORMAT`` :setting:`worker_task_log_format`
  135. ``CELERYD_TIMER`` :setting:`worker_timer`
  136. ``CELERYD_TIMER_PRECISION`` :setting:`worker_timer_precision`
  137. ===================================== ==============================================
  138. Configuration Directives
  139. ========================
  140. .. _conf-datetime:
  141. General settings
  142. ----------------
  143. .. setting:: accept_content
  144. ``accept_content``
  145. ~~~~~~~~~~~~~~~~~~
  146. A white-list of content-types/serializers to allow.
  147. If a message is received that is not in this list then
  148. the message will be discarded with an error.
  149. By default any content type is enabled (including pickle and yaml)
  150. so make sure untrusted parties do not have access to your broker.
  151. See :ref:`guide-security` for more.
  152. Example::
  153. # using serializer name
  154. accept_content = ['json']
  155. # or the actual content-type (MIME)
  156. accept_content = ['application/json']
  157. Time and date settings
  158. ----------------------
  159. .. setting:: enable_utc
  160. ``enable_utc``
  161. ~~~~~~~~~~~~~~
  162. .. versionadded:: 2.5
  163. If enabled dates and times in messages will be converted to use
  164. the UTC timezone.
  165. Note that workers running Celery versions below 2.5 will assume a local
  166. timezone for all messages, so only enable if all workers have been
  167. upgraded.
  168. Enabled by default since version 3.0.
  169. .. setting:: timezone
  170. ``timezone``
  171. ~~~~~~~~~~~~
  172. Configure Celery to use a custom time zone.
  173. The timezone value can be any time zone supported by the `pytz`_
  174. library.
  175. If not set the UTC timezone is used. For backwards compatibility
  176. there is also a :setting:`enable_utc` setting, and this is set
  177. to false the system local timezone is used instead.
  178. .. _`pytz`: http://pypi.python.org/pypi/pytz/
  179. .. _conf-tasks:
  180. Task settings
  181. -------------
  182. .. setting:: task_annotations
  183. ``task_annotations``
  184. ~~~~~~~~~~~~~~~~~~~~
  185. This setting can be used to rewrite any task attribute from the
  186. configuration. The setting can be a dict, or a list of annotation
  187. objects that filter for tasks and return a map of attributes
  188. to change.
  189. This will change the ``rate_limit`` attribute for the ``tasks.add``
  190. task:
  191. .. code-block:: python
  192. task_annotations = {'tasks.add': {'rate_limit': '10/s'}}
  193. or change the same for all tasks:
  194. .. code-block:: python
  195. task_annotations = {'*': {'rate_limit': '10/s'}}
  196. You can change methods too, for example the ``on_failure`` handler:
  197. .. code-block:: python
  198. def my_on_failure(self, exc, task_id, args, kwargs, einfo):
  199. print('Oh no! Task failed: {0!r}'.format(exc))
  200. task_annotations = {'*': {'on_failure': my_on_failure}}
  201. If you need more flexibility then you can use objects
  202. instead of a dict to choose which tasks to annotate:
  203. .. code-block:: python
  204. class MyAnnotate(object):
  205. def annotate(self, task):
  206. if task.name.startswith('tasks.'):
  207. return {'rate_limit': '10/s'}
  208. task_annotations = (MyAnnotate(), {other,})
  209. .. setting:: task_compression
  210. ``task_compression``
  211. ~~~~~~~~~~~~~~~~~~~~
  212. Default compression used for task messages.
  213. Can be ``gzip``, ``bzip2`` (if available), or any custom
  214. compression schemes registered in the Kombu compression registry.
  215. The default is to send uncompressed messages.
  216. .. setting:: task_protocol
  217. ``task_protocol``
  218. ~~~~~~~~~~~~~~~~~
  219. Default task message protocol version.
  220. Supports protocols: 1 and 2 (default is 1 for backwards compatibility).
  221. .. setting:: task_serializer
  222. ``task_serializer``
  223. ~~~~~~~~~~~~~~~~~~~
  224. A string identifying the default serialization method to use. Can be
  225. `pickle` (default), `json`, `yaml`, `msgpack` or any custom serialization
  226. methods that have been registered with :mod:`kombu.serialization.registry`.
  227. .. seealso::
  228. :ref:`calling-serializers`.
  229. .. setting:: task_publish_retry
  230. ``task_publish_retry``
  231. ~~~~~~~~~~~~~~~~~~~~~~
  232. .. versionadded:: 2.2
  233. Decides if publishing task messages will be retried in the case
  234. of connection loss or other connection errors.
  235. See also :setting:`task_publish_retry_policy`.
  236. Enabled by default.
  237. .. setting:: task_publish_retry_policy
  238. ``task_publish_retry_policy``
  239. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  240. .. versionadded:: 2.2
  241. Defines the default policy when retrying publishing a task message in
  242. the case of connection loss or other connection errors.
  243. See :ref:`calling-retry` for more information.
  244. .. _conf-task-execution:
  245. Task execution settings
  246. -----------------------
  247. .. setting:: task_always_eager
  248. ``task_always_eager``
  249. ~~~~~~~~~~~~~~~~~~~~~
  250. If this is :const:`True`, all tasks will be executed locally by blocking until
  251. the task returns. ``apply_async()`` and ``Task.delay()`` will return
  252. an :class:`~celery.result.EagerResult` instance, which emulates the API
  253. and behavior of :class:`~celery.result.AsyncResult`, except the result
  254. is already evaluated.
  255. That is, tasks will be executed locally instead of being sent to
  256. the queue.
  257. .. setting:: task_eager_propagates
  258. ``task_eager_propagates``
  259. ~~~~~~~~~~~~~~~~~~~~~~~~~
  260. If this is :const:`True`, eagerly executed tasks (applied by `task.apply()`,
  261. or when the :setting:`task_always_eager` setting is enabled), will
  262. propagate exceptions.
  263. It's the same as always running ``apply()`` with ``throw=True``.
  264. .. setting:: task_remote_tracebacks
  265. ``task_remote_tracebacks``
  266. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  267. If enabled task results will include the workers stack when re-raising
  268. task errors.
  269. This requires the :pypi:`tblib` library, which can be installed using
  270. :command:`pip`:
  271. .. code-block:: console
  272. $ pip install 'tblib>=1.3.0'
  273. .. setting:: task_ignore_result
  274. ``task_ignore_result``
  275. ~~~~~~~~~~~~~~~~~~~~~~
  276. Whether to store the task return values or not (tombstones).
  277. If you still want to store errors, just not successful return values,
  278. you can set :setting:`task_store_errors_even_if_ignored`.
  279. .. setting:: task_store_errors_even_if_ignored
  280. ``task_store_errors_even_if_ignored``
  281. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  282. If set, the worker stores all task errors in the result store even if
  283. :attr:`Task.ignore_result <celery.task.base.Task.ignore_result>` is on.
  284. .. setting:: task_track_started
  285. ``task_track_started``
  286. ~~~~~~~~~~~~~~~~~~~~~~
  287. If :const:`True` the task will report its status as 'started' when the
  288. task is executed by a worker. The default value is :const:`False` as
  289. the normal behavior is to not report that level of granularity. Tasks
  290. are either pending, finished, or waiting to be retried. Having a 'started'
  291. state can be useful for when there are long running tasks and there is a
  292. need to report which task is currently running.
  293. .. setting:: task_time_limit
  294. ``task_time_limit``
  295. ~~~~~~~~~~~~~~~~~~~
  296. Task hard time limit in seconds. The worker processing the task will
  297. be killed and replaced with a new one when this is exceeded.
  298. .. setting:: task_soft_time_limit
  299. ``task_soft_time_limit``
  300. ~~~~~~~~~~~~~~~~~~~~~~~~
  301. Task soft time limit in seconds.
  302. The :exc:`~@SoftTimeLimitExceeded` exception will be
  303. raised when this is exceeded. The task can catch this to
  304. e.g. clean up before the hard time limit comes.
  305. Example:
  306. .. code-block:: python
  307. from celery.exceptions import SoftTimeLimitExceeded
  308. @app.task
  309. def mytask():
  310. try:
  311. return do_work()
  312. except SoftTimeLimitExceeded:
  313. cleanup_in_a_hurry()
  314. .. setting:: task_acks_late
  315. ``task_acks_late``
  316. ~~~~~~~~~~~~~~~~~~
  317. Late ack means the task messages will be acknowledged **after** the task
  318. has been executed, not *just before*, which is the default behavior.
  319. .. seealso::
  320. FAQ: :ref:`faq-acks_late-vs-retry`.
  321. .. setting:: task_reject_on_worker_lost
  322. ``task_reject_on_worker_lost``
  323. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  324. Even if :setting:`task_acks_late` is enabled, the worker will
  325. acknowledge tasks when the worker process executing them abruptly
  326. exits or is signaled (e.g. :sig:`KILL`/:sig:`INT`, etc).
  327. Setting this to true allows the message to be re-queued instead,
  328. so that the task will execute again by the same worker, or another
  329. worker.
  330. .. warning::
  331. Enabling this can cause message loops; make sure you know
  332. what you're doing.
  333. .. setting:: task_default_rate_limit
  334. ``task_default_rate_limit``
  335. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  336. The global default rate limit for tasks.
  337. This value is used for tasks that does not have a custom rate limit
  338. The default is no rate limit.
  339. .. seealso::
  340. The setting:`worker_disable_rate_limits` setting can
  341. disable all rate limits.
  342. .. _conf-result-backend:
  343. Task result backend settings
  344. ----------------------------
  345. .. setting:: result_backend
  346. ``result_backend``
  347. ~~~~~~~~~~~~~~~~~~
  348. The backend used to store task results (tombstones).
  349. Disabled by default.
  350. Can be one of the following:
  351. * ``rpc``
  352. Send results back as AMQP messages
  353. See :ref:`conf-rpc-result-backend`.
  354. * ``database``
  355. Use a relational database supported by `SQLAlchemy`_.
  356. See :ref:`conf-database-result-backend`.
  357. * ``redis``
  358. Use `Redis`_ to store the results.
  359. See :ref:`conf-redis-result-backend`.
  360. * ``cache``
  361. Use `Memcached`_ to store the results.
  362. See :ref:`conf-cache-result-backend`.
  363. * ``cassandra``
  364. Use `Cassandra`_ to store the results.
  365. See :ref:`conf-cassandra-result-backend`.
  366. * ``elasticsearch``
  367. Use `Elasticsearch`_ to store the results.
  368. See :ref:`conf-elasticsearch-result-backend`.
  369. * ``ironcache``
  370. Use `IronCache`_ to store the results.
  371. See :ref:`conf-ironcache-result-backend`.
  372. * ``couchbase``
  373. Use `Couchbase`_ to store the results.
  374. See :ref:`conf-couchbase-result-backend`.
  375. * ``couchdb``
  376. Use `CouchDB`_ to store the results.
  377. See :ref:`conf-couchdb-result-backend`.
  378. * ``filesystem``
  379. Use a shared directory to store the results.
  380. See :ref:`conf-filesystem-result-backend`.
  381. * ``consul``
  382. Use the `Consul`_ K/V store to store the results
  383. See :ref:`conf-consul-result-backend`.
  384. .. warning:
  385. While the AMQP result backend is very efficient, you must make sure
  386. you only receive the same result once. See :doc:`userguide/calling`).
  387. .. _`SQLAlchemy`: http://sqlalchemy.org
  388. .. _`Memcached`: http://memcached.org
  389. .. _`Redis`: http://redis.io
  390. .. _`Cassandra`: http://cassandra.apache.org/
  391. .. _`Elasticsearch`: https://aws.amazon.com/elasticsearch-service/
  392. .. _`IronCache`: http://www.iron.io/cache
  393. .. _`CouchDB`: http://www.couchdb.com/
  394. .. _`Couchbase`: http://www.couchbase.com/
  395. .. _`Consul`: http://consul.io/
  396. .. setting:: result_serializer
  397. ``result_serializer``
  398. ~~~~~~~~~~~~~~~~~~~~~
  399. Result serialization format. Default is ``pickle``. See
  400. :ref:`calling-serializers` for information about supported
  401. serialization formats.
  402. .. setting:: result_compression
  403. ``result_compression``
  404. ~~~~~~~~~~~~~~~~~~~~~~
  405. Optional compression method used for task results.
  406. Supports the same options as the :setting:`task_serializer` setting.
  407. Default is no compression.
  408. .. setting:: result_expires
  409. ``result_expires``
  410. ~~~~~~~~~~~~~~~~~~
  411. Time (in seconds, or a :class:`~datetime.timedelta` object) for when after
  412. stored task tombstones will be deleted.
  413. A built-in periodic task will delete the results after this time
  414. (``celery.backend_cleanup``), assuming that ``celery beat`` is
  415. enabled. The task runs daily at 4am.
  416. A value of :const:`None` or 0 means results will never expire (depending
  417. on backend specifications).
  418. Default is to expire after 1 day.
  419. .. note::
  420. For the moment this only works with the AMQP, database, cache,
  421. and Redis result backends.
  422. When using the database backend, `celery beat` must be
  423. running for the results to be expired.
  424. .. setting:: result_cache_max
  425. ``result_cache_max``
  426. ~~~~~~~~~~~~~~~~~~~~
  427. Enables client caching of results, which can be useful for the old deprecated
  428. 'amqp' backend where the result is unavailable as soon as one result instance
  429. consumes it.
  430. This is the total number of results to cache before older results are evicted.
  431. A value of 0 or None means no limit, and a value of :const:`-1`
  432. will disable the cache.
  433. Disabled by default.
  434. .. _conf-database-result-backend:
  435. Database backend settings
  436. -------------------------
  437. Database URL Examples
  438. ~~~~~~~~~~~~~~~~~~~~~
  439. To use the database backend you have to configure the
  440. :setting:`result_backend` setting with a connection URL and the ``db+``
  441. prefix:
  442. .. code-block:: python
  443. result_backend = 'db+scheme://user:password@host:port/dbname'
  444. Examples::
  445. # sqlite (filename)
  446. result_backend = 'db+sqlite:///results.sqlite'
  447. # mysql
  448. result_backend = 'db+mysql://scott:tiger@localhost/foo'
  449. # postgresql
  450. result_backend = 'db+postgresql://scott:tiger@localhost/mydatabase'
  451. # oracle
  452. result_backend = 'db+oracle://scott:tiger@127.0.0.1:1521/sidname'
  453. .. code-block:: python
  454. Please see `Supported Databases`_ for a table of supported databases,
  455. and `Connection String`_ for more information about connection
  456. strings (which is the part of the URI that comes after the ``db+`` prefix).
  457. .. _`Supported Databases`:
  458. http://www.sqlalchemy.org/docs/core/engines.html#supported-databases
  459. .. _`Connection String`:
  460. http://www.sqlalchemy.org/docs/core/engines.html#database-urls
  461. .. setting:: sqlalchemy_dburi
  462. ``sqlalchemy_dburi``
  463. ~~~~~~~~~~~~~~~~~~~~
  464. This setting is no longer used as it's now possible to specify
  465. the database URL directly in the :setting:`result_backend` setting.
  466. .. setting:: sqlalchemy_engine_options
  467. ``sqlalchemy_engine_options``
  468. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  469. To specify additional SQLAlchemy database engine options you can use
  470. the :setting:`sqlalchmey_engine_options` setting::
  471. # echo enables verbose logging from SQLAlchemy.
  472. app.conf.sqlalchemy_engine_options = {'echo': True}
  473. .. setting:: sqlalchemy_short_lived_sessions
  474. ``sqlalchemy_short_lived_sessions``
  475. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  476. Short lived sessions are disabled by default. If enabled they can drastically reduce
  477. performance, especially on systems processing lots of tasks. This option is useful
  478. on low-traffic workers that experience errors as a result of cached database connections
  479. going stale through inactivity. For example, intermittent errors like
  480. `(OperationalError) (2006, 'MySQL server has gone away')` can be fixed by enabling
  481. short lived sessions. This option only affects the database backend.
  482. .. setting:: sqlalchemy_table_names
  483. ``sqlalchemy_table_names``
  484. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  485. When SQLAlchemy is configured as the result backend, Celery automatically
  486. creates two tables to store result meta-data for tasks. This setting allows
  487. you to customize the table names:
  488. .. code-block:: python
  489. # use custom table names for the database result backend.
  490. sqlalchemy_table_names = {
  491. 'task': 'myapp_taskmeta',
  492. 'group': 'myapp_groupmeta',
  493. }
  494. .. _conf-rpc-result-backend:
  495. RPC backend settings
  496. --------------------
  497. .. setting:: result_exchange
  498. ``result_exchange``
  499. ~~~~~~~~~~~~~~~~~~~
  500. Name of the exchange to publish results in. Default is `celeryresults`.
  501. .. setting:: result_exchange_type
  502. ``result_exchange_type``
  503. ~~~~~~~~~~~~~~~~~~~~~~~~
  504. The exchange type of the result exchange. Default is to use a `direct`
  505. exchange.
  506. .. setting:: result_persistent
  507. ``result_persistent``
  508. ~~~~~~~~~~~~~~~~~~~~~
  509. If set to :const:`True`, result messages will be persistent. This means the
  510. messages will not be lost after a broker restart. The default is for the
  511. results to be transient.
  512. Example configuration
  513. ~~~~~~~~~~~~~~~~~~~~~
  514. .. code-block:: python
  515. result_backend = 'rpc://'
  516. result_persistent = False
  517. .. _conf-cache-result-backend:
  518. Cache backend settings
  519. ----------------------
  520. .. note::
  521. The cache backend supports the :pypi:`pylibmc` and `python-memcached`
  522. libraries. The latter is used only if :pypi:`pylibmc` is not installed.
  523. Using a single Memcached server:
  524. .. code-block:: python
  525. result_backend = 'cache+memcached://127.0.0.1:11211/'
  526. Using multiple Memcached servers:
  527. .. code-block:: python
  528. result_backend = """
  529. cache+memcached://172.19.26.240:11211;172.19.26.242:11211/
  530. """.strip()
  531. The "memory" backend stores the cache in memory only:
  532. .. code-block:: python
  533. result_backend = 'cache'
  534. cache_backend = 'memory'
  535. .. setting:: cache_backend_options
  536. ``cache_backend_options``
  537. ~~~~~~~~~~~~~~~~~~~~~~~~~
  538. You can set :pypi:`pylibmc` options using the :setting:`cache_backend_options`
  539. setting:
  540. .. code-block:: python
  541. cache_backend_options = {
  542. 'binary': True,
  543. 'behaviors': {'tcp_nodelay': True},
  544. }
  545. .. setting:: cache_backend
  546. ``cache_backend``
  547. ~~~~~~~~~~~~~~~~~
  548. This setting is no longer used as it's now possible to specify
  549. the cache backend directly in the :setting:`result_backend` setting.
  550. .. _conf-redis-result-backend:
  551. Redis backend settings
  552. ----------------------
  553. Configuring the backend URL
  554. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  555. .. note::
  556. The Redis backend requires the :pypi:`redis` library:
  557. http://pypi.python.org/pypi/redis/
  558. To install the redis package use `pip` or `easy_install`:
  559. .. code-block:: console
  560. $ pip install redis
  561. This backend requires the :setting:`result_backend`
  562. setting to be set to a Redis URL::
  563. result_backend = 'redis://:password@host:port/db'
  564. For example::
  565. result_backend = 'redis://localhost/0'
  566. which is the same as::
  567. result_backend = 'redis://'
  568. The fields of the URL are defined as follows:
  569. #. ``password``
  570. Password used to connect to the database.
  571. #. ``host``
  572. Host name or IP address of the Redis server. e.g. `localhost`.
  573. #. ``port``
  574. Port to the Redis server. Default is 6379.
  575. #. ``db``
  576. Database number to use. Default is 0.
  577. The db can include an optional leading slash.
  578. .. setting:: redis_max_connections
  579. ``redis_max_connections``
  580. ~~~~~~~~~~~~~~~~~~~~~~~~~
  581. Maximum number of connections available in the Redis connection
  582. pool used for sending and retrieving results.
  583. .. setting:: redis_socket_timeout
  584. ``redis_socket_timeout``
  585. ~~~~~~~~~~~~~~~~~~~~~~~~
  586. Socket timeout for connections to Redis from the result backend
  587. in seconds (int/float)
  588. Default is 5 seconds.
  589. .. _conf-cassandra-result-backend:
  590. Cassandra backend settings
  591. --------------------------
  592. .. note::
  593. This Cassandra backend driver requires :pypi:`cassandra-driver`.
  594. https://pypi.python.org/pypi/cassandra-driver
  595. To install, use `pip` or `easy_install`:
  596. .. code-block:: console
  597. $ pip install cassandra-driver
  598. This backend requires the following configuration directives to be set.
  599. .. setting:: cassandra_servers
  600. ``cassandra_servers``
  601. ~~~~~~~~~~~~~~~~~~~~~
  602. List of ``host`` Cassandra servers. e.g.::
  603. cassandra_servers = ['localhost']
  604. .. setting:: cassandra_port
  605. ``cassandra_port``
  606. ~~~~~~~~~~~~~~~~~~
  607. Port to contact the Cassandra servers on. Default is 9042.
  608. .. setting:: cassandra_keyspace
  609. ``cassandra_keyspace``
  610. ~~~~~~~~~~~~~~~~~~~~~~
  611. The key-space in which to store the results. e.g.::
  612. cassandra_keyspace = 'tasks_keyspace'
  613. .. setting:: cassandra_table
  614. ``cassandra_table``
  615. ~~~~~~~~~~~~~~~~~~~
  616. The table (column family) in which to store the results. e.g.::
  617. cassandra_table = 'tasks'
  618. .. setting:: cassandra_read_consistency
  619. ``cassandra_read_consistency``
  620. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  621. The read consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``,
  622. ``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``.
  623. .. setting:: cassandra_write_consistency
  624. ``cassandra_write_consistency``
  625. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  626. The write consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``,
  627. ``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``.
  628. .. setting:: cassandra_entry_ttl
  629. ``cassandra_entry_ttl``
  630. ~~~~~~~~~~~~~~~~~~~~~~~
  631. Time-to-live for status entries. They will expire and be removed after that many seconds
  632. after adding. Default (None) means they will never expire.
  633. .. setting:: cassandra_auth_provider
  634. ``cassandra_auth_provider``
  635. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  636. AuthProvider class within ``cassandra.auth`` module to use. Values can be
  637. ``PlainTextAuthProvider`` or ``SaslAuthProvider``.
  638. .. setting:: cassandra_auth_kwargs
  639. ``cassandra_auth_kwargs``
  640. ~~~~~~~~~~~~~~~~~~~~~~~~~
  641. Named arguments to pass into the authentication provider. e.g.:
  642. .. code-block:: python
  643. cassandra_auth_kwargs = {
  644. username: 'cassandra',
  645. password: 'cassandra'
  646. }
  647. Example configuration
  648. ~~~~~~~~~~~~~~~~~~~~~
  649. .. code-block:: python
  650. cassandra_servers = ['localhost']
  651. cassandra_keyspace = 'celery'
  652. cassandra_table = 'tasks'
  653. cassandra_read_consistency = 'ONE'
  654. cassandra_write_consistency = 'ONE'
  655. cassandra_entry_ttl = 86400
  656. .. _conf-elasticsearch-result-backend:
  657. Elasticsearch backend settings
  658. ------------------------------
  659. To use `Elasticsearch`_ as the result backend you simply need to
  660. configure the :setting:`result_backend` setting with the correct URL.
  661. Example configuration
  662. ~~~~~~~~~~~~~~~~~~~~~
  663. .. code-block:: python
  664. result_backend = 'elasticsearch://example.com:9200/index_name/doc_type'
  665. .. _conf-riak-result-backend:
  666. Riak backend settings
  667. ---------------------
  668. .. note::
  669. The Riak backend requires the :pypi:`riak` library:
  670. http://pypi.python.org/pypi/riak/
  671. To install the :pypi:`riak` package use `pip` or `easy_install`:
  672. .. code-block:: console
  673. $ pip install riak
  674. This backend requires the :setting:`result_backend`
  675. setting to be set to a Riak URL::
  676. result_backend = 'riak://host:port/bucket'
  677. For example::
  678. result_backend = 'riak://localhost/celery
  679. which is the same as::
  680. result_backend = 'riak://'
  681. The fields of the URL are defined as follows:
  682. #. ``host``
  683. Host name or IP address of the Riak server. e.g. `'localhost'`.
  684. #. ``port``
  685. Port to the Riak server using the protobuf protocol. Default is 8087.
  686. #. ``bucket``
  687. Bucket name to use. Default is `celery`.
  688. The bucket needs to be a string with ASCII characters only.
  689. Alternatively, this backend can be configured with the following configuration directives.
  690. .. setting:: riak_backend_settings
  691. ``riak_backend_settings``
  692. ~~~~~~~~~~~~~~~~~~~~~~~~~
  693. This is a dict supporting the following keys:
  694. * ``host``
  695. The host name of the Riak server. Defaults to ``"localhost"``.
  696. * ``port``
  697. The port the Riak server is listening to. Defaults to 8087.
  698. * ``bucket``
  699. The bucket name to connect to. Defaults to "celery".
  700. * ``protocol``
  701. The protocol to use to connect to the Riak server. This is not configurable
  702. via :setting:`result_backend`
  703. .. _conf-ironcache-result-backend:
  704. IronCache backend settings
  705. --------------------------
  706. .. note::
  707. The IronCache backend requires the :pypi:`iron_celery` library:
  708. http://pypi.python.org/pypi/iron_celery
  709. To install the iron_celery package use `pip` or `easy_install`:
  710. .. code-block:: console
  711. $ pip install iron_celery
  712. IronCache is configured via the URL provided in :setting:`result_backend`, for example::
  713. result_backend = 'ironcache://project_id:token@'
  714. Or to change the cache name::
  715. ironcache:://project_id:token@/awesomecache
  716. For more information, see: https://github.com/iron-io/iron_celery
  717. .. _conf-couchbase-result-backend:
  718. Couchbase backend settings
  719. --------------------------
  720. .. note::
  721. The Couchbase backend requires the :pypi:`couchbase` library:
  722. https://pypi.python.org/pypi/couchbase
  723. To install the :pypi:`couchbase` package use `pip` or `easy_install`:
  724. .. code-block:: console
  725. $ pip install couchbase
  726. This backend can be configured via the :setting:`result_backend`
  727. set to a Couchbase URL:
  728. .. code-block:: python
  729. result_backend = 'couchbase://username:password@host:port/bucket'
  730. .. setting:: couchbase_backend_settings
  731. ``couchbase_backend_settings``
  732. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  733. This is a dict supporting the following keys:
  734. * ``host``
  735. Host name of the Couchbase server. Defaults to ``localhost``.
  736. * ``port``
  737. The port the Couchbase server is listening to. Defaults to ``8091``.
  738. * ``bucket``
  739. The default bucket the Couchbase server is writing to.
  740. Defaults to ``default``.
  741. * ``username``
  742. User name to authenticate to the Couchbase server as (optional).
  743. * ``password``
  744. Password to authenticate to the Couchbase server (optional).
  745. .. _conf-couchdb-result-backend:
  746. CouchDB backend settings
  747. ------------------------
  748. .. note::
  749. The CouchDB backend requires the :pypi:`pycouchdb` library:
  750. https://pypi.python.org/pypi/pycouchdb
  751. To install the Couchbase package use :command:`pip`, or :command:`easy_install`:
  752. .. code-block:: console
  753. $ pip install pycouchdb
  754. This backend can be configured via the :setting:`result_backend`
  755. set to a CouchDB URL::
  756. result_backend = 'couchdb://username:password@host:port/container'
  757. The URL is formed out of the following parts:
  758. * ``username``
  759. User name to authenticate to the CouchDB server as (optional).
  760. * ``password``
  761. Password to authenticate to the CouchDB server (optional).
  762. * ``host``
  763. Host name of the CouchDB server. Defaults to ``localhost``.
  764. * ``port``
  765. The port the CouchDB server is listening to. Defaults to ``8091``.
  766. * ``container``
  767. The default container the CouchDB server is writing to.
  768. Defaults to ``default``.
  769. .. _conf-filesystem-result-backend:
  770. File-system backend settings
  771. ----------------------------
  772. This backend can be configured using a file URL, for example::
  773. CELERY_RESULT_BACKEND = 'file:///var/celery/results'
  774. The configured directory needs to be shared and writable by all servers using
  775. the backend.
  776. If you are trying Celery on a single system you can simply use the backend
  777. without any further configuration. For larger clusters you could use NFS,
  778. `GlusterFS`_, CIFS, `HDFS`_ (using FUSE) or any other file-system.
  779. .. _`GlusterFS`: http://www.gluster.org/
  780. .. _`HDFS`: http://hadoop.apache.org/
  781. .. _conf-consul-result-backend:
  782. Consul K/V store backend settings
  783. ---------------------------------
  784. The Consul backend can be configured using a URL, for example:
  785. CELERY_RESULT_BACKEND = 'consul://localhost:8500/'
  786. The backend will storage results in the K/V store of Consul
  787. as individual keys.
  788. The backend supports auto expire of results using TTLs in Consul.
  789. .. _conf-messaging:
  790. Message Routing
  791. ---------------
  792. .. _conf-messaging-routing:
  793. .. setting:: task_queues
  794. ``task_queues``
  795. ~~~~~~~~~~~~~~~
  796. Most users will not want to specify this setting and should rather use
  797. the :ref:`automatic routing facilities <routing-automatic>`.
  798. If you really want to configure advanced routing, this setting should
  799. be a list of :class:`kombu.Queue` objects the worker will consume from.
  800. Note that workers can be overridden this setting via the
  801. :option:`-Q <celery worker -Q>` option, or individual queues from this
  802. list (by name) can be excluded using the :option:`-X <celery worker -X>`
  803. option.
  804. Also see :ref:`routing-basics` for more information.
  805. The default is a queue/exchange/binding key of ``celery``, with
  806. exchange type ``direct``.
  807. See also :setting:`task_routes`
  808. .. setting:: task_routes
  809. ``task_routes``
  810. ~~~~~~~~~~~~~~~
  811. A list of routers, or a single router used to route tasks to queues.
  812. When deciding the final destination of a task the routers are consulted
  813. in order.
  814. A router can be specified as either:
  815. * A function with the signature ``(name, args, kwargs,
  816. options, task=None, **kwargs)``
  817. * A string which provides the path to a router function.
  818. * A dict containing router specification:
  819. Will be converted to a :class:`celery.routes.MapRoute` instance.
  820. * A list of ``(pattern, route)`` tuples:
  821. Will be converted to a :class:`celery.routes.MapRoute` instance.
  822. Examples:
  823. .. code-block:: python
  824. task_routes = {
  825. 'celery.ping': 'default',
  826. 'mytasks.add': 'cpu-bound',
  827. 'feed.tasks.*': 'feeds', # <-- glob pattern
  828. re.compile(r'(image|video)\.tasks\..*'): 'media', # <-- regex
  829. 'video.encode': {
  830. 'queue': 'video',
  831. 'exchange': 'media'
  832. 'routing_key': 'media.video.encode',
  833. },
  834. }
  835. task_routes = ('myapp.tasks.route_task', {'celery.ping': 'default})
  836. Where ``myapp.tasks.route_task`` could be:
  837. .. code-block:: python
  838. def route_task(self, name, args, kwargs, options, task=None, **kwargs):
  839. if task == 'celery.ping':
  840. return {'queue': 'default'}
  841. ``route_task`` may return a string or a dict. A string then means
  842. it's a queue name in :setting:`task_queues`, a dict means it's a custom route.
  843. When sending tasks, the routers are consulted in order. The first
  844. router that doesn't return ``None`` is the route to use. The message options
  845. is then merged with the found route settings, where the routers settings
  846. have priority.
  847. Example if :func:`~celery.execute.apply_async` has these arguments:
  848. .. code-block:: python
  849. Task.apply_async(immediate=False, exchange='video',
  850. routing_key='video.compress')
  851. and a router returns:
  852. .. code-block:: python
  853. {'immediate': True, 'exchange': 'urgent'}
  854. the final message options will be:
  855. .. code-block:: python
  856. immediate=True, exchange='urgent', routing_key='video.compress'
  857. (and any default message options defined in the
  858. :class:`~celery.task.base.Task` class)
  859. Values defined in :setting:`task_routes` have precedence over values defined in
  860. :setting:`task_queues` when merging the two.
  861. With the follow settings:
  862. .. code-block:: python
  863. task_queues = {
  864. 'cpubound': {
  865. 'exchange': 'cpubound',
  866. 'routing_key': 'cpubound',
  867. },
  868. }
  869. task_routes = {
  870. 'tasks.add': {
  871. 'queue': 'cpubound',
  872. 'routing_key': 'tasks.add',
  873. 'serializer': 'json',
  874. },
  875. }
  876. The final routing options for ``tasks.add`` will become:
  877. .. code-block:: javascript
  878. {'exchange': 'cpubound',
  879. 'routing_key': 'tasks.add',
  880. 'serializer': 'json'}
  881. See :ref:`routers` for more examples.
  882. .. setting:: task_queue_ha_policy
  883. ``task_queue_ha_policy``
  884. ~~~~~~~~~~~~~~~~~~~~~~~~
  885. :brokers: RabbitMQ
  886. This will set the default HA policy for a queue, and the value
  887. can either be a string (usually ``all``):
  888. .. code-block:: python
  889. task_queue_ha_policy = 'all'
  890. Using 'all' will replicate the queue to all current nodes,
  891. Or you can give it a list of nodes to replicate to:
  892. .. code-block:: python
  893. task_queue_ha_policy = ['rabbit@host1', 'rabbit@host2']
  894. Using a list will implicitly set ``x-ha-policy`` to 'nodes' and
  895. ``x-ha-policy-params`` to the given list of nodes.
  896. See http://www.rabbitmq.com/ha.html for more information.
  897. .. setting:: task_queue_max_priority
  898. ``task_queue_max_priority``
  899. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  900. :brokers: RabbitMQ
  901. See :ref:`routing-options-rabbitmq-priorities`.
  902. .. setting:: worker_direct
  903. ``worker_direct``
  904. ~~~~~~~~~~~~~~~~~
  905. This option enables so that every worker has a dedicated queue,
  906. so that tasks can be routed to specific workers.
  907. The queue name for each worker is automatically generated based on
  908. the worker hostname and a ``.dq`` suffix, using the ``C.dq`` exchange.
  909. For example the queue name for the worker with node name ``w1@example.com``
  910. becomes::
  911. w1@example.com.dq
  912. Then you can route the task to the task by specifying the hostname
  913. as the routing key and the ``C.dq`` exchange::
  914. task_routes = {
  915. 'tasks.add': {'exchange': 'C.dq', 'routing_key': 'w1@example.com'}
  916. }
  917. .. setting:: task_create_missing_queues
  918. ``task_create_missing_queues``
  919. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  920. If enabled (default), any queues specified that are not defined in
  921. :setting:`task_queues` will be automatically created. See
  922. :ref:`routing-automatic`.
  923. .. setting:: task_default_queue
  924. ``task_default_queue``
  925. ~~~~~~~~~~~~~~~~~~~~~~
  926. The name of the default queue used by `.apply_async` if the message has
  927. no route or no custom queue has been specified.
  928. This queue must be listed in :setting:`task_queues`.
  929. If :setting:`task_queues` is not specified then it is automatically
  930. created containing one queue entry, where this name is used as the name of
  931. that queue.
  932. The default is: `celery`.
  933. .. seealso::
  934. :ref:`routing-changing-default-queue`
  935. .. setting:: task_default_exchange
  936. ``task_default_exchange``
  937. ~~~~~~~~~~~~~~~~~~~~~~~~~
  938. Name of the default exchange to use when no custom exchange is
  939. specified for a key in the :setting:`task_queues` setting.
  940. The default is: `celery`.
  941. .. setting:: task_default_exchange_type
  942. ``task_default_exchange_type``
  943. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  944. Default exchange type used when no custom exchange type is specified
  945. for a key in the :setting:`task_queues` setting.
  946. The default is: `direct`.
  947. .. setting:: task_default_routing_key
  948. ``task_default_routing_key``
  949. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  950. The default routing key used when no custom routing key
  951. is specified for a key in the :setting:`task_queues` setting.
  952. The default is: `celery`.
  953. .. setting:: task_default_delivery_mode
  954. ``task_default_delivery_mode``
  955. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  956. Can be `transient` or `persistent`. The default is to send
  957. persistent messages.
  958. .. _conf-broker-settings:
  959. Broker Settings
  960. ---------------
  961. .. setting:: broker_url
  962. ``broker_url``
  963. ~~~~~~~~~~~~~~
  964. Default broker URL. This must be a URL in the form of::
  965. transport://userid:password@hostname:port/virtual_host
  966. Only the scheme part (``transport://``) is required, the rest
  967. is optional, and defaults to the specific transports default values.
  968. The transport part is the broker implementation to use, and the
  969. default is ``amqp``, which uses ``librabbitmq`` by default or falls back to
  970. ``pyamqp`` if that is not installed. Also there are many other choices including
  971. ``redis``, ``beanstalk``, ``sqlalchemy``, ``django``, ``mongodb``,
  972. ``couchdb``.
  973. It can also be a fully qualified path to your own transport implementation.
  974. More than one broker URL, of the same transport, can also be specified.
  975. The broker URLs can be passed in as a single string that is semicolon delimited::
  976. broker_url = 'transport://userid:password@hostname:port//;transport://userid:password@hostname:port//'
  977. Or as a list::
  978. broker_url = [
  979. 'transport://userid:password@localhost:port//',
  980. 'transport://userid:password@hostname:port//'
  981. ]
  982. The brokers will then be used in the :setting:`broker_failover_strategy`.
  983. See :ref:`kombu:connection-urls` in the Kombu documentation for more
  984. information.
  985. .. setting:: broker_read_url
  986. .. setting:: broker_write_url
  987. ``broker_read_url`` / ``broker_write_url``
  988. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  989. These settings can be configured, instead of :setting:`broker_url` to specify
  990. different connection parameters for broker connections used for consuming and
  991. producing.
  992. Example::
  993. broker_read_url = 'amqp://user:pass@broker.example.com:56721'
  994. broker_write_url = 'amqp://user:pass@broker.example.com:56722'
  995. Both options can also be specified as a list for failover alternates, see
  996. :setting:`broker_url` for more information.
  997. .. setting:: broker_failover_strategy
  998. ``broker_failover_strategy``
  999. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1000. Default failover strategy for the broker Connection object. If supplied,
  1001. may map to a key in 'kombu.connection.failover_strategies', or be a reference
  1002. to any method that yields a single item from a supplied list.
  1003. Example::
  1004. # Random failover strategy
  1005. def random_failover_strategy(servers):
  1006. it = list(it) # don't modify callers list
  1007. shuffle = random.shuffle
  1008. for _ in repeat(None):
  1009. shuffle(it)
  1010. yield it[0]
  1011. broker_failover_strategy = random_failover_strategy
  1012. .. setting:: broker_heartbeat
  1013. ``broker_heartbeat``
  1014. ~~~~~~~~~~~~~~~~~~~~
  1015. :transports supported: ``pyamqp``
  1016. It's not always possible to detect connection loss in a timely
  1017. manner using TCP/IP alone, so AMQP defines something called heartbeats
  1018. that's is used both by the client and the broker to detect if
  1019. a connection was closed.
  1020. Heartbeats are disabled by default.
  1021. If the heartbeat value is 10 seconds, then
  1022. the heartbeat will be monitored at the interval specified
  1023. by the :setting:`broker_heartbeat_checkrate` setting, which by default is
  1024. double the rate of the heartbeat value
  1025. (so for the default 10 seconds, the heartbeat is checked every 5 seconds).
  1026. .. setting:: broker_heartbeat_checkrate
  1027. ``broker_heartbeat_checkrate``
  1028. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1029. :transports supported: ``pyamqp``
  1030. At intervals the worker will monitor that the broker has not missed
  1031. too many heartbeats. The rate at which this is checked is calculated
  1032. by dividing the :setting:`broker_heartbeat` value with this value,
  1033. so if the heartbeat is 10.0 and the rate is the default 2.0, the check
  1034. will be performed every 5 seconds (twice the heartbeat sending rate).
  1035. .. setting:: broker_use_ssl
  1036. ``broker_use_ssl``
  1037. ~~~~~~~~~~~~~~~~~~
  1038. :transports supported: ``pyamqp``, ``redis``
  1039. Toggles SSL usage on broker connection and SSL settings.
  1040. If ``True`` the connection will use SSL with default SSL settings.
  1041. If set to a dict, will configure SSL connection according to the specified
  1042. policy. The format used is python `ssl.wrap_socket()
  1043. options <https://docs.python.org/3/library/ssl.html#ssl.wrap_socket>`_.
  1044. Default is ``False`` (no SSL).
  1045. Note that SSL socket is generally served on a separate port by the broker.
  1046. Example providing a client cert and validating the server cert against a custom
  1047. certificate authority:
  1048. .. code-block:: python
  1049. import ssl
  1050. broker_use_ssl = {
  1051. 'keyfile': '/var/ssl/private/worker-key.pem',
  1052. 'certfile': '/var/ssl/amqp-server-cert.pem',
  1053. 'ca_certs': '/var/ssl/myca.pem',
  1054. 'cert_reqs': ssl.CERT_REQUIRED
  1055. }
  1056. .. warning::
  1057. Be careful using ``broker_use_ssl=True``. It is possible that your default
  1058. configuration will not validate the server cert at all. Please read Python
  1059. `ssl module security
  1060. considerations <https://docs.python.org/3/library/ssl.html#ssl-security>`_.
  1061. .. setting:: broker_pool_limit
  1062. ``broker_pool_limit``
  1063. ~~~~~~~~~~~~~~~~~~~~~
  1064. .. versionadded:: 2.3
  1065. The maximum number of connections that can be open in the connection pool.
  1066. The pool is enabled by default since version 2.5, with a default limit of ten
  1067. connections. This number can be tweaked depending on the number of
  1068. threads/green-threads (eventlet/gevent) using a connection. For example
  1069. running eventlet with 1000 greenlets that use a connection to the broker,
  1070. contention can arise and you should consider increasing the limit.
  1071. If set to :const:`None` or 0 the connection pool will be disabled and
  1072. connections will be established and closed for every use.
  1073. Default (since 2.5) is to use a pool of 10 connections.
  1074. .. setting:: broker_connection_timeout
  1075. ``broker_connection_timeout``
  1076. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1077. The default timeout in seconds before we give up establishing a connection
  1078. to the AMQP server. Default is 4 seconds. This setting is disabled when using
  1079. gevent.
  1080. .. setting:: broker_connection_retry
  1081. ``broker_connection_retry``
  1082. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1083. Automatically try to re-establish the connection to the AMQP broker if lost.
  1084. The time between retries is increased for each retry, and is
  1085. not exhausted before :setting:`broker_connection_max_retries` is
  1086. exceeded.
  1087. This behavior is on by default.
  1088. .. setting:: broker_connection_max_retries
  1089. ``broker_connection_max_retries``
  1090. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1091. Maximum number of retries before we give up re-establishing a connection
  1092. to the AMQP broker.
  1093. If this is set to :const:`0` or :const:`None`, we will retry forever.
  1094. Default is 100 retries.
  1095. .. setting:: broker_login_method
  1096. ``broker_login_method``
  1097. ~~~~~~~~~~~~~~~~~~~~~~~
  1098. Set custom amqp login method, default is ``AMQPLAIN``.
  1099. .. setting:: broker_transport_options
  1100. ``broker_transport_options``
  1101. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1102. .. versionadded:: 2.2
  1103. A dict of additional options passed to the underlying transport.
  1104. See your transport user manual for supported options (if any).
  1105. Example setting the visibility timeout (supported by SQS
  1106. transports):
  1107. .. code-block:: python
  1108. broker_transport_options = {'visibility_timeout': 18000} # 5 hours
  1109. .. _conf-worker:
  1110. Worker
  1111. ------
  1112. .. setting:: imports
  1113. ``imports``
  1114. ~~~~~~~~~~~
  1115. A sequence of modules to import when the worker starts.
  1116. This is used to specify the task modules to import, but also
  1117. to import signal handlers and additional remote control commands, etc.
  1118. The modules will be imported in the original order.
  1119. .. setting:: include
  1120. ``include``
  1121. ~~~~~~~~~~~
  1122. Exact same semantics as :setting:`imports`, but can be used as a means
  1123. to have different import categories.
  1124. The modules in this setting are imported after the modules in
  1125. :setting:`imports`.
  1126. .. _conf-concurrency:
  1127. .. setting:: worker_concurrency
  1128. ``worker_concurrency``
  1129. ~~~~~~~~~~~~~~~~~~~~~~
  1130. The number of concurrent worker processes/threads/green threads executing
  1131. tasks.
  1132. If you're doing mostly I/O you can have more processes,
  1133. but if mostly CPU-bound, try to keep it close to the
  1134. number of CPUs on your machine. If not set, the number of CPUs/cores
  1135. on the host will be used.
  1136. Defaults to the number of available CPUs.
  1137. .. setting:: worker_prefetch_multiplier
  1138. ``worker_prefetch_multiplier``
  1139. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1140. How many messages to prefetch at a time multiplied by the number of
  1141. concurrent processes. The default is 4 (four messages for each
  1142. process). The default setting is usually a good choice, however -- if you
  1143. have very long running tasks waiting in the queue and you have to start the
  1144. workers, note that the first worker to start will receive four times the
  1145. number of messages initially. Thus the tasks may not be fairly distributed
  1146. to the workers.
  1147. To disable prefetching, set :setting:`worker_prefetch_multiplier` to 1.
  1148. Changing that setting to 0 will allow the worker to keep consuming
  1149. as many messages as it wants.
  1150. For more on prefetching, read :ref:`optimizing-prefetch-limit`
  1151. .. note::
  1152. Tasks with ETA/countdown are not affected by prefetch limits.
  1153. .. setting:: worker_lost_wait
  1154. ``worker_lost_wait``
  1155. ~~~~~~~~~~~~~~~~~~~~
  1156. In some cases a worker may be killed without proper cleanup,
  1157. and the worker may have published a result before terminating.
  1158. This value specifies how long we wait for any missing results before
  1159. raising a :exc:`@WorkerLostError` exception.
  1160. Default is 10.0
  1161. .. setting:: worker_max_tasks_per_child
  1162. ``worker_max_tasks_per_child``
  1163. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1164. Maximum number of tasks a pool worker process can execute before
  1165. it's replaced with a new one. Default is no limit.
  1166. .. setting:: worker_max_memory_per_child
  1167. ``worker_max_memory_per_child``
  1168. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1169. Maximum amount of resident memory that may be consumed by a
  1170. worker before it will be replaced by a new worker. If a single
  1171. task causes a worker to exceed this limit, the task will be
  1172. completed, and the worker will be replaced afterwards. Default:
  1173. no limit.
  1174. .. setting:: worker_disable_rate_limits
  1175. ``worker_disable_rate_limits``
  1176. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1177. Disable all rate limits, even if tasks has explicit rate limits set.
  1178. .. setting:: worker_state_db
  1179. ``worker_state_db``
  1180. ~~~~~~~~~~~~~~~~~~~
  1181. Name of the file used to stores persistent worker state (like revoked tasks).
  1182. Can be a relative or absolute path, but be aware that the suffix `.db`
  1183. may be appended to the file name (depending on Python version).
  1184. Can also be set via the :option:`celery worker --statedb` argument.
  1185. Not enabled by default.
  1186. .. setting:: worker_timer_precision
  1187. ``worker_timer_precision``
  1188. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1189. Set the maximum time in seconds that the ETA scheduler can sleep between
  1190. rechecking the schedule. Default is 1 second.
  1191. Setting this value to 1 second means the schedulers precision will
  1192. be 1 second. If you need near millisecond precision you can set this to 0.1.
  1193. .. setting:: worker_enable_remote_control
  1194. ``worker_enable_remote_control``
  1195. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1196. Specify if remote control of the workers is enabled.
  1197. Default is :const:`True`.
  1198. .. _conf-events:
  1199. Events
  1200. ------
  1201. .. setting:: worker_send_task_events
  1202. ``worker_send_task_events``
  1203. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1204. Send task-related events so that tasks can be monitored using tools like
  1205. `flower`. Sets the default value for the workers
  1206. :option:`-E <celery worker -E>` argument.
  1207. .. setting:: task_send_sent_event
  1208. ``task_send_sent_event``
  1209. ~~~~~~~~~~~~~~~~~~~~~~~~
  1210. .. versionadded:: 2.2
  1211. If enabled, a :event:`task-sent` event will be sent for every task so tasks can be
  1212. tracked before they are consumed by a worker.
  1213. Disabled by default.
  1214. .. setting:: event_queue_ttl
  1215. ``event_queue_ttl``
  1216. ~~~~~~~~~~~~~~~~~~~
  1217. :transports supported: ``amqp``
  1218. Message expiry time in seconds (int/float) for when messages sent to a monitor clients
  1219. event queue is deleted (``x-message-ttl``)
  1220. For example, if this value is set to 10 then a message delivered to this queue
  1221. will be deleted after 10 seconds.
  1222. Disabled by default.
  1223. .. setting:: event_queue_expires
  1224. ``event_queue_expires``
  1225. ~~~~~~~~~~~~~~~~~~~~~~~
  1226. :transports supported: ``amqp``
  1227. Expiry time in seconds (int/float) for when after a monitor clients
  1228. event queue will be deleted (``x-expires``).
  1229. Default is never, relying on the queue auto-delete setting.
  1230. .. setting:: event_queue_prefix
  1231. ``event_queue_prefix``
  1232. ~~~~~~~~~~~~~~~~~~~~~~
  1233. The prefix to use for event receiver queue names.
  1234. The default is ``celeryev``.
  1235. .. setting:: event_serializer
  1236. ``event_serializer``
  1237. ~~~~~~~~~~~~~~~~~~~~
  1238. Message serialization format used when sending event messages.
  1239. Default is ``json``. See :ref:`calling-serializers`.
  1240. .. _conf-logging:
  1241. Logging
  1242. -------
  1243. .. setting:: worker_hijack_root_logger
  1244. ``worker_hijack_root_logger``
  1245. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1246. .. versionadded:: 2.2
  1247. By default any previously configured handlers on the root logger will be
  1248. removed. If you want to customize your own logging handlers, then you
  1249. can disable this behavior by setting
  1250. `worker_hijack_root_logger = False`.
  1251. .. note::
  1252. Logging can also be customized by connecting to the
  1253. :signal:`celery.signals.setup_logging` signal.
  1254. .. setting:: worker_log_color
  1255. ``worker_log_color``
  1256. ~~~~~~~~~~~~~~~~~~~~
  1257. Enables/disables colors in logging output by the Celery apps.
  1258. By default colors are enabled if the app is logging to a real
  1259. terminal, and not a file.
  1260. .. setting:: worker_log_format
  1261. ``worker_log_format``
  1262. ~~~~~~~~~~~~~~~~~~~~~
  1263. The format to use for log messages.
  1264. Default is::
  1265. [%(asctime)s: %(levelname)s/%(processName)s] %(message)s
  1266. See the Python :mod:`logging` module for more information about log
  1267. formats.
  1268. .. setting:: worker_task_log_format
  1269. ``worker_task_log_format``
  1270. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1271. The format to use for log messages logged in tasks.
  1272. Default is:
  1273. .. code-block:: text
  1274. [%(asctime)s: %(levelname)s/%(processName)s]
  1275. [%(task_name)s(%(task_id)s)] %(message)s
  1276. See the Python :mod:`logging` module for more information about log
  1277. formats.
  1278. .. setting:: worker_redirect_stdouts
  1279. ``worker_redirect_stdouts``
  1280. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1281. If enabled `stdout` and `stderr` will be redirected
  1282. to the current logger.
  1283. Enabled by default.
  1284. Used by :program:`celery worker` and :program:`celery beat`.
  1285. .. setting:: worker_redirect_stdouts_level
  1286. ``worker_redirect_stdouts_level``
  1287. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1288. The log level output to `stdout` and `stderr` is logged as.
  1289. Can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
  1290. :const:`ERROR` or :const:`CRITICAL`.
  1291. Default is :const:`WARNING`.
  1292. .. _conf-security:
  1293. Security
  1294. --------
  1295. .. setting:: security_key
  1296. ``security_key``
  1297. ~~~~~~~~~~~~~~~~
  1298. .. versionadded:: 2.5
  1299. The relative or absolute path to a file containing the private key
  1300. used to sign messages when :ref:`message-signing` is used.
  1301. .. setting:: security_certificate
  1302. ``security_certificate``
  1303. ~~~~~~~~~~~~~~~~~~~~~~~~
  1304. .. versionadded:: 2.5
  1305. The relative or absolute path to an X.509 certificate file
  1306. used to sign messages when :ref:`message-signing` is used.
  1307. .. setting:: security_cert_store
  1308. ``security_cert_store``
  1309. ~~~~~~~~~~~~~~~~~~~~~~~
  1310. .. versionadded:: 2.5
  1311. The directory containing X.509 certificates used for
  1312. :ref:`message-signing`. Can be a glob with wild-cards,
  1313. (for example :file:`/etc/certs/*.pem`).
  1314. .. _conf-custom-components:
  1315. Custom Component Classes (advanced)
  1316. -----------------------------------
  1317. .. setting:: worker_pool
  1318. ``worker_pool``
  1319. ~~~~~~~~~~~~~~~
  1320. Name of the pool class used by the worker.
  1321. .. admonition:: Eventlet/Gevent
  1322. Never use this option to select the eventlet or gevent pool.
  1323. You must use the :option:`-P <celery worker -P>` option to
  1324. :program:`celery worker` instead, to ensure the monkey patches
  1325. are not applied too late, causing things to break in strange ways.
  1326. Default is ``celery.concurrency.prefork:TaskPool``.
  1327. .. setting:: worker_pool_restarts
  1328. ``worker_pool_restarts``
  1329. ~~~~~~~~~~~~~~~~~~~~~~~~
  1330. If enabled the worker pool can be restarted using the
  1331. :control:`pool_restart` remote control command.
  1332. Disabled by default.
  1333. .. setting:: worker_consumer
  1334. ``worker_consumer``
  1335. ~~~~~~~~~~~~~~~~~~~
  1336. Name of the consumer class used by the worker.
  1337. Default is :class:`celery.worker.consumer.Consumer`
  1338. .. setting:: worker_timer
  1339. ``worker_timer``
  1340. ~~~~~~~~~~~~~~~~
  1341. Name of the ETA scheduler class used by the worker.
  1342. Default is :class:`kombu.async.hub.timer.Timer`, or set by the
  1343. pool implementation.
  1344. .. _conf-celerybeat:
  1345. Beat Settings (:program:`celery beat`)
  1346. --------------------------------------
  1347. .. setting:: beat_schedule
  1348. ``beat_schedule``
  1349. ~~~~~~~~~~~~~~~~~
  1350. The periodic task schedule used by :mod:`~celery.bin.beat`.
  1351. See :ref:`beat-entries`.
  1352. .. setting:: beat_scheduler
  1353. ``beat_scheduler``
  1354. ~~~~~~~~~~~~~~~~~~
  1355. The default scheduler class. Default is ``celery.beat:PersistentScheduler``.
  1356. Can also be set via the :option:`celery beat -S` argument.
  1357. .. setting:: beat_schedule_filename
  1358. ``beat_schedule_filename``
  1359. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1360. Name of the file used by `PersistentScheduler` to store the last run times
  1361. of periodic tasks. Can be a relative or absolute path, but be aware that the
  1362. suffix `.db` may be appended to the file name (depending on Python version).
  1363. Can also be set via the :option:`celery beat --schedule` argument.
  1364. .. setting:: beat_sync_every
  1365. ``beat_sync_every``
  1366. ~~~~~~~~~~~~~~~~~~~
  1367. The number of periodic tasks that can be called before another database sync
  1368. is issued.
  1369. Defaults to 0 (sync based on timing - default of 3 minutes as determined by
  1370. scheduler.sync_every). If set to 1, beat will call sync after every task
  1371. message sent.
  1372. .. setting:: beat_max_loop_interval
  1373. ``beat_max_loop_interval``
  1374. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1375. The maximum number of seconds :mod:`~celery.bin.beat` can sleep
  1376. between checking the schedule.
  1377. The default for this value is scheduler specific.
  1378. For the default celery beat scheduler the value is 300 (5 minutes),
  1379. but for e.g. the :pypi:`django-celery` database scheduler it is 5 seconds
  1380. because the schedule may be changed externally, and so it must take
  1381. changes to the schedule into account.
  1382. Also when running celery beat embedded (:option:`-B <celery worker -B>`)
  1383. on Jython as a thread the max interval is overridden and set to 1 so
  1384. that it's possible to shut down in a timely manner.