configuration.rst 67 KB

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