configuration.rst 60 KB

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