configuration.rst 58 KB

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