configuration.rst 66 KB

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