configuration.rst 64 KB

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