configuration.rst 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473
  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_TASK_ACKS_LATE`` :setting:`task_acks_late`
  94. ``CELERY_TASK_ALWAYS_EAGER`` :setting:`task_always_eager`
  95. ``CELERY_TASK_ANNOTATIONS`` :setting:`task_annotations`
  96. ``CELERY_TASK_COMPRESSION`` :setting:`task_compression`
  97. ``CELERY_TASK_CREATE_MISSING_QUEUES`` :setting:`task_create_missing_queues`
  98. ``CELERY_TASK_DEFAULT_DELIVERY_MODE`` :setting:`task_default_delivery_mode`
  99. ``CELERY_TASK_DEFAULT_EXCHANGE`` :setting:`task_default_exchange`
  100. ``CELERY_TASK_DEFAULT_EXCHANGE_TYPE`` :setting:`task_default_exchange_type`
  101. ``CELERY_TASK_DEFAULT_QUEUE`` :setting:`task_default_queue`
  102. ``CELERY_TASK_DEFAULT_RATE_LIMIT`` :setting:`task_default_rate_limit`
  103. ``CELERY_TASK_DEFAULT_ROUTING_KEY`` :setting:`task_default_routing_key`
  104. ``CELERY_TASK_EAGER_PROPAGATES`` :setting:`task_eager_propagates`
  105. ``CELERY_TASK_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_TASK_QUEUES`` :setting:`task_queues`
  109. ``CELERY_TASK_ROUTES`` :setting:`task_routes`
  110. ``CELERY_TASK_SEND_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_backend_use_ssl
  594. ``redis_backend_use_ssl``
  595. ~~~~~~~~~~~~~~~~~~~~~~~~~
  596. Default: Disabled.
  597. The Redis backend supports SSL. The valid values of this options are the same
  598. as :setting:`broker_use_ssl`.
  599. .. setting:: redis_max_connections
  600. ``redis_max_connections``
  601. ~~~~~~~~~~~~~~~~~~~~~~~~~
  602. Default: No limit.
  603. Maximum number of connections available in the Redis connection
  604. pool used for sending and retrieving results.
  605. .. setting:: redis_socket_connect_timeout
  606. ``redis_socket_connect_timeout``
  607. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  608. .. versionadded:: 5.0.1
  609. Default: :const:`None`
  610. Socket timeout for connections to Redis from the result backend
  611. in seconds (int/float)
  612. .. setting:: redis_socket_timeout
  613. ``redis_socket_timeout``
  614. ~~~~~~~~~~~~~~~~~~~~~~~~
  615. Default: 120.0 seconds.
  616. Socket timeout for reading/writing operations to the Redis server
  617. in seconds (int/float), used by the redis result backend.
  618. .. _conf-cassandra-result-backend:
  619. Cassandra backend settings
  620. --------------------------
  621. .. note::
  622. This Cassandra backend driver requires :pypi:`cassandra-driver`.
  623. To install, use :command:`pip`:
  624. .. code-block:: console
  625. $ pip install celery[cassandra]
  626. See :ref:`bundles` for information on combining multiple extension
  627. requirements.
  628. This backend requires the following configuration directives to be set.
  629. .. setting:: cassandra_servers
  630. ``cassandra_servers``
  631. ~~~~~~~~~~~~~~~~~~~~~
  632. Default: ``[]`` (empty list).
  633. List of ``host`` Cassandra servers. For example::
  634. cassandra_servers = ['localhost']
  635. .. setting:: cassandra_port
  636. ``cassandra_port``
  637. ~~~~~~~~~~~~~~~~~~
  638. Default: 9042.
  639. Port to contact the Cassandra servers on.
  640. .. setting:: cassandra_keyspace
  641. ``cassandra_keyspace``
  642. ~~~~~~~~~~~~~~~~~~~~~~
  643. Default: None.
  644. The key-space in which to store the results. For example::
  645. cassandra_keyspace = 'tasks_keyspace'
  646. .. setting:: cassandra_table
  647. ``cassandra_table``
  648. ~~~~~~~~~~~~~~~~~~~
  649. Default: None.
  650. The table (column family) in which to store the results. For example::
  651. cassandra_table = 'tasks'
  652. .. setting:: cassandra_read_consistency
  653. ``cassandra_read_consistency``
  654. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  655. Default: None.
  656. The read consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``,
  657. ``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``.
  658. .. setting:: cassandra_write_consistency
  659. ``cassandra_write_consistency``
  660. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  661. Default: None.
  662. The write consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``,
  663. ``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``.
  664. .. setting:: cassandra_entry_ttl
  665. ``cassandra_entry_ttl``
  666. ~~~~~~~~~~~~~~~~~~~~~~~
  667. Default: None.
  668. Time-to-live for status entries. They will expire and be removed after that many seconds
  669. after adding. A value of :const:`None` (default) means they will never expire.
  670. .. setting:: cassandra_auth_provider
  671. ``cassandra_auth_provider``
  672. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  673. Default: :const:`None`.
  674. AuthProvider class within ``cassandra.auth`` module to use. Values can be
  675. ``PlainTextAuthProvider`` or ``SaslAuthProvider``.
  676. .. setting:: cassandra_auth_kwargs
  677. ``cassandra_auth_kwargs``
  678. ~~~~~~~~~~~~~~~~~~~~~~~~~
  679. Default: ``{}`` (empty mapping).
  680. Named arguments to pass into the authentication provider. For example:
  681. .. code-block:: python
  682. cassandra_auth_kwargs = {
  683. username: 'cassandra',
  684. password: 'cassandra'
  685. }
  686. Example configuration
  687. ~~~~~~~~~~~~~~~~~~~~~
  688. .. code-block:: python
  689. cassandra_servers = ['localhost']
  690. cassandra_keyspace = 'celery'
  691. cassandra_table = 'tasks'
  692. cassandra_read_consistency = 'ONE'
  693. cassandra_write_consistency = 'ONE'
  694. cassandra_entry_ttl = 86400
  695. .. _conf-elasticsearch-result-backend:
  696. Elasticsearch backend settings
  697. ------------------------------
  698. To use `Elasticsearch`_ as the result backend you simply need to
  699. configure the :setting:`result_backend` setting with the correct URL.
  700. Example configuration
  701. ~~~~~~~~~~~~~~~~~~~~~
  702. .. code-block:: python
  703. result_backend = 'elasticsearch://example.com:9200/index_name/doc_type'
  704. .. setting:: elasticsearch_retry_on_timeout
  705. ``elasticsearch_retry_on_timeout``
  706. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  707. Default: :const:`False`
  708. Should timeout trigger a retry on different node?
  709. .. setting:: elasticsearch_max_retries
  710. ``elasticsearch_max_retries``
  711. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  712. Default: 3.
  713. Maximum number of retries before an exception is propagated.
  714. .. setting:: elasticsearch_timeout
  715. ``elasticsearch_timeout``
  716. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  717. Default: 10.0 seconds.
  718. Global timeout,used by the elasticsearch result backend.
  719. .. _conf-riak-result-backend:
  720. Riak backend settings
  721. ---------------------
  722. .. note::
  723. The Riak backend requires the :pypi:`riak` library.
  724. To install the this package use :command:`pip`:
  725. .. code-block:: console
  726. $ pip install celery[riak]
  727. See :ref:`bundles` for information on combining multiple extension
  728. requirements.
  729. This backend requires the :setting:`result_backend`
  730. setting to be set to a Riak URL::
  731. result_backend = 'riak://host:port/bucket'
  732. For example::
  733. result_backend = 'riak://localhost/celery
  734. is the same as::
  735. result_backend = 'riak://'
  736. The fields of the URL are defined as follows:
  737. #. ``host``
  738. Host name or IP address of the Riak server (e.g., `'localhost'`).
  739. #. ``port``
  740. Port to the Riak server using the protobuf protocol. Default is 8087.
  741. #. ``bucket``
  742. Bucket name to use. Default is `celery`.
  743. The bucket needs to be a string with ASCII characters only.
  744. Alternatively, this backend can be configured with the following configuration directives.
  745. .. setting:: riak_backend_settings
  746. ``riak_backend_settings``
  747. ~~~~~~~~~~~~~~~~~~~~~~~~~
  748. Default: ``{}`` (empty mapping).
  749. This is a dict supporting the following keys:
  750. * ``host``
  751. The host name of the Riak server. Defaults to ``"localhost"``.
  752. * ``port``
  753. The port the Riak server is listening to. Defaults to 8087.
  754. * ``bucket``
  755. The bucket name to connect to. Defaults to "celery".
  756. * ``protocol``
  757. The protocol to use to connect to the Riak server. This isn't configurable
  758. via :setting:`result_backend`
  759. .. _conf-dynamodb-result-backend:
  760. AWS DynamoDB backend settings
  761. -----------------------------
  762. .. note::
  763. The Dynamodb backend requires the :pypi:`boto3` library.
  764. To install this package use :command:`pip`:
  765. .. code-block:: console
  766. $ pip install celery[dynamodb]
  767. See :ref:`bundles` for information on combining multiple extension
  768. requirements.
  769. This backend requires the :setting:`result_backend`
  770. setting to be set to a DynamoDB URL::
  771. result_backend = 'dynamodb://aws_access_key_id:aws_secret_access_key@region:port/table?read=n&write=m'
  772. For example, specifying the AWS region and the table name::
  773. result_backend = 'dynamodb://@us-east-1/celery_results
  774. or retrieving AWS configuration parameters from the environment, using the default table name (``celery``)
  775. and specifying read and write provisioned throughput::
  776. result_backend = 'dynamodb://@/?read=5&write=5'
  777. or using the `downloadable version <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html>`_
  778. of DynamoDB
  779. `locally <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.Endpoint.html>`_::
  780. result_backend = 'dynamodb://@localhost:8000
  781. The fields of the URL are defined as follows:
  782. #. ``aws_access_key_id & aws_secret_access_key``
  783. The credentials for accessing AWS API resources. These can also be resolved
  784. by the :pypi:`boto3` library from various sources, as
  785. described `here <http://boto3.readthedocs.io/en/latest/guide/configuration.html#configuring-credentials>`_.
  786. #. ``region``
  787. The AWS region, e.g. ``us-east-1`` or ``localhost`` for the `Downloadable Version <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html>`_.
  788. See the :pypi:`boto3` library `documentation <http://boto3.readthedocs.io/en/latest/guide/configuration.html#environment-variable-configuration>`_
  789. for definition options.
  790. #. ``port``
  791. The listening port of the local DynamoDB instance, if you are using the downloadable version.
  792. If you have not specified the ``region`` parameter as ``localhost``,
  793. setting this parameter has **no effect**.
  794. #. ``table``
  795. Table name to use. Default is ``celery``.
  796. See the `DynamoDB Naming Rules <http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-naming-rules>`_
  797. for information on the allowed characters and length.
  798. #. ``read & write``
  799. The Read & Write Capacity Units for the created DynamoDB table. Default is ``1`` for both read and write.
  800. More details can be found in the `Provisioned Throughput documentation <http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ProvisionedThroughput.html>`_.
  801. .. _conf-ironcache-result-backend:
  802. IronCache backend settings
  803. --------------------------
  804. .. note::
  805. The IronCache backend requires the :pypi:`iron_celery` library:
  806. To install this package use :command:`pip`:
  807. .. code-block:: console
  808. $ pip install iron_celery
  809. IronCache is configured via the URL provided in :setting:`result_backend`, for example::
  810. result_backend = 'ironcache://project_id:token@'
  811. Or to change the cache name::
  812. ironcache:://project_id:token@/awesomecache
  813. For more information, see: https://github.com/iron-io/iron_celery
  814. .. _conf-couchbase-result-backend:
  815. Couchbase backend settings
  816. --------------------------
  817. .. note::
  818. The Couchbase backend requires the :pypi:`couchbase` library.
  819. To install this package use :command:`pip`:
  820. .. code-block:: console
  821. $ pip install celery[couchbase]
  822. See :ref:`bundles` for instructions how to combine multiple extension
  823. requirements.
  824. This backend can be configured via the :setting:`result_backend`
  825. set to a Couchbase URL:
  826. .. code-block:: python
  827. result_backend = 'couchbase://username:password@host:port/bucket'
  828. .. setting:: couchbase_backend_settings
  829. ``couchbase_backend_settings``
  830. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  831. Default: ``{}`` (empty mapping).
  832. This is a dict supporting the following keys:
  833. * ``host``
  834. Host name of the Couchbase server. Defaults to ``localhost``.
  835. * ``port``
  836. The port the Couchbase server is listening to. Defaults to ``8091``.
  837. * ``bucket``
  838. The default bucket the Couchbase server is writing to.
  839. Defaults to ``default``.
  840. * ``username``
  841. User name to authenticate to the Couchbase server as (optional).
  842. * ``password``
  843. Password to authenticate to the Couchbase server (optional).
  844. .. _conf-couchdb-result-backend:
  845. CouchDB backend settings
  846. ------------------------
  847. .. note::
  848. The CouchDB backend requires the :pypi:`pycouchdb` library:
  849. To install this Couchbase package use :command:`pip`:
  850. .. code-block:: console
  851. $ pip install celery[couchdb]
  852. See :ref:`bundles` for information on combining multiple extension
  853. requirements.
  854. This backend can be configured via the :setting:`result_backend`
  855. set to a CouchDB URL::
  856. result_backend = 'couchdb://username:password@host:port/container'
  857. The URL is formed out of the following parts:
  858. * ``username``
  859. User name to authenticate to the CouchDB server as (optional).
  860. * ``password``
  861. Password to authenticate to the CouchDB server (optional).
  862. * ``host``
  863. Host name of the CouchDB server. Defaults to ``localhost``.
  864. * ``port``
  865. The port the CouchDB server is listening to. Defaults to ``8091``.
  866. * ``container``
  867. The default container the CouchDB server is writing to.
  868. Defaults to ``default``.
  869. .. _conf-filesystem-result-backend:
  870. File-system backend settings
  871. ----------------------------
  872. This backend can be configured using a file URL, for example::
  873. CELERY_RESULT_BACKEND = 'file:///var/celery/results'
  874. The configured directory needs to be shared and writable by all servers using
  875. the backend.
  876. If you're trying Celery on a single system you can simply use the backend
  877. without any further configuration. For larger clusters you could use NFS,
  878. `GlusterFS`_, CIFS, `HDFS`_ (using FUSE), or any other file-system.
  879. .. _`GlusterFS`: http://www.gluster.org/
  880. .. _`HDFS`: http://hadoop.apache.org/
  881. .. _conf-consul-result-backend:
  882. Consul K/V store backend settings
  883. ---------------------------------
  884. The Consul backend can be configured using a URL, for example:
  885. CELERY_RESULT_BACKEND = 'consul://localhost:8500/'
  886. The backend will storage results in the K/V store of Consul
  887. as individual keys.
  888. The backend supports auto expire of results using TTLs in Consul.
  889. .. _conf-messaging:
  890. Message Routing
  891. ---------------
  892. .. _conf-messaging-routing:
  893. .. setting:: task_queues
  894. ``task_queues``
  895. ~~~~~~~~~~~~~~~
  896. Default: :const:`None` (queue taken from default queue settings).
  897. Most users will not want to specify this setting and should rather use
  898. the :ref:`automatic routing facilities <routing-automatic>`.
  899. If you really want to configure advanced routing, this setting should
  900. be a list of :class:`kombu.Queue` objects the worker will consume from.
  901. Note that workers can be overridden this setting via the
  902. :option:`-Q <celery worker -Q>` option, or individual queues from this
  903. list (by name) can be excluded using the :option:`-X <celery worker -X>`
  904. option.
  905. Also see :ref:`routing-basics` for more information.
  906. The default is a queue/exchange/binding key of ``celery``, with
  907. exchange type ``direct``.
  908. See also :setting:`task_routes`
  909. .. setting:: task_routes
  910. ``task_routes``
  911. ~~~~~~~~~~~~~~~
  912. Default: :const:`None`.
  913. A list of routers, or a single router used to route tasks to queues.
  914. When deciding the final destination of a task the routers are consulted
  915. in order.
  916. A router can be specified as either:
  917. * A function with the signature ``(name, args, kwargs,
  918. options, task=None, **kwargs)``
  919. * A string providing the path to a router function.
  920. * A dict containing router specification:
  921. Will be converted to a :class:`celery.routes.MapRoute` instance.
  922. * A list of ``(pattern, route)`` tuples:
  923. Will be converted to a :class:`celery.routes.MapRoute` instance.
  924. Examples:
  925. .. code-block:: python
  926. task_routes = {
  927. 'celery.ping': 'default',
  928. 'mytasks.add': 'cpu-bound',
  929. 'feed.tasks.*': 'feeds', # <-- glob pattern
  930. re.compile(r'(image|video)\.tasks\..*'): 'media', # <-- regex
  931. 'video.encode': {
  932. 'queue': 'video',
  933. 'exchange': 'media'
  934. 'routing_key': 'media.video.encode',
  935. },
  936. }
  937. task_routes = ('myapp.tasks.route_task', {'celery.ping': 'default})
  938. Where ``myapp.tasks.route_task`` could be:
  939. .. code-block:: python
  940. def route_task(self, name, args, kwargs, options, task=None, **kw):
  941. if task == 'celery.ping':
  942. return {'queue': 'default'}
  943. ``route_task`` may return a string or a dict. A string then means
  944. it's a queue name in :setting:`task_queues`, a dict means it's a custom route.
  945. When sending tasks, the routers are consulted in order. The first
  946. router that doesn't return ``None`` is the route to use. The message options
  947. is then merged with the found route settings, where the routers settings
  948. have priority.
  949. Example if :func:`~celery.execute.apply_async` has these arguments:
  950. .. code-block:: python
  951. Task.apply_async(immediate=False, exchange='video',
  952. routing_key='video.compress')
  953. and a router returns:
  954. .. code-block:: python
  955. {'immediate': True, 'exchange': 'urgent'}
  956. the final message options will be:
  957. .. code-block:: python
  958. immediate=True, exchange='urgent', routing_key='video.compress'
  959. (and any default message options defined in the
  960. :class:`~celery.task.base.Task` class)
  961. Values defined in :setting:`task_routes` have precedence over values defined in
  962. :setting:`task_queues` when merging the two.
  963. With the follow settings:
  964. .. code-block:: python
  965. task_queues = {
  966. 'cpubound': {
  967. 'exchange': 'cpubound',
  968. 'routing_key': 'cpubound',
  969. },
  970. }
  971. task_routes = {
  972. 'tasks.add': {
  973. 'queue': 'cpubound',
  974. 'routing_key': 'tasks.add',
  975. 'serializer': 'json',
  976. },
  977. }
  978. The final routing options for ``tasks.add`` will become:
  979. .. code-block:: javascript
  980. {'exchange': 'cpubound',
  981. 'routing_key': 'tasks.add',
  982. 'serializer': 'json'}
  983. See :ref:`routers` for more examples.
  984. .. setting:: task_queue_ha_policy
  985. ``task_queue_ha_policy``
  986. ~~~~~~~~~~~~~~~~~~~~~~~~
  987. :brokers: RabbitMQ
  988. Default: :const:`None`.
  989. This will set the default HA policy for a queue, and the value
  990. can either be a string (usually ``all``):
  991. .. code-block:: python
  992. task_queue_ha_policy = 'all'
  993. Using 'all' will replicate the queue to all current nodes,
  994. Or you can give it a list of nodes to replicate to:
  995. .. code-block:: python
  996. task_queue_ha_policy = ['rabbit@host1', 'rabbit@host2']
  997. Using a list will implicitly set ``x-ha-policy`` to 'nodes' and
  998. ``x-ha-policy-params`` to the given list of nodes.
  999. See http://www.rabbitmq.com/ha.html for more information.
  1000. .. setting:: task_queue_max_priority
  1001. ``task_queue_max_priority``
  1002. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1003. :brokers: RabbitMQ
  1004. Default: :const:`None`.
  1005. See :ref:`routing-options-rabbitmq-priorities`.
  1006. .. setting:: worker_direct
  1007. ``worker_direct``
  1008. ~~~~~~~~~~~~~~~~~
  1009. Default: Disabled.
  1010. This option enables so that every worker has a dedicated queue,
  1011. so that tasks can be routed to specific workers.
  1012. The queue name for each worker is automatically generated based on
  1013. the worker hostname and a ``.dq`` suffix, using the ``C.dq`` exchange.
  1014. For example the queue name for the worker with node name ``w1@example.com``
  1015. becomes::
  1016. w1@example.com.dq
  1017. Then you can route the task to the task by specifying the hostname
  1018. as the routing key and the ``C.dq`` exchange::
  1019. task_routes = {
  1020. 'tasks.add': {'exchange': 'C.dq', 'routing_key': 'w1@example.com'}
  1021. }
  1022. .. setting:: task_create_missing_queues
  1023. ``task_create_missing_queues``
  1024. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1025. Default: Enabled.
  1026. If enabled (default), any queues specified that aren't defined in
  1027. :setting:`task_queues` will be automatically created. See
  1028. :ref:`routing-automatic`.
  1029. .. setting:: task_default_queue
  1030. ``task_default_queue``
  1031. ~~~~~~~~~~~~~~~~~~~~~~
  1032. Default: ``"celery"``.
  1033. The name of the default queue used by `.apply_async` if the message has
  1034. no route or no custom queue has been specified.
  1035. This queue must be listed in :setting:`task_queues`.
  1036. If :setting:`task_queues` isn't specified then it's automatically
  1037. created containing one queue entry, where this name is used as the name of
  1038. that queue.
  1039. .. seealso::
  1040. :ref:`routing-changing-default-queue`
  1041. .. setting:: task_default_exchange
  1042. ``task_default_exchange``
  1043. ~~~~~~~~~~~~~~~~~~~~~~~~~
  1044. Default: ``"celery"``.
  1045. Name of the default exchange to use when no custom exchange is
  1046. specified for a key in the :setting:`task_queues` setting.
  1047. .. setting:: task_default_exchange_type
  1048. ``task_default_exchange_type``
  1049. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1050. Default: ``"direct"``.
  1051. Default exchange type used when no custom exchange type is specified
  1052. for a key in the :setting:`task_queues` setting.
  1053. .. setting:: task_default_routing_key
  1054. ``task_default_routing_key``
  1055. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1056. Default: ``"celery"``.
  1057. The default routing key used when no custom routing key
  1058. is specified for a key in the :setting:`task_queues` setting.
  1059. .. setting:: task_default_delivery_mode
  1060. ``task_default_delivery_mode``
  1061. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1062. Default: ``"persistent"``.
  1063. Can be `transient` (messages not written to disk) or `persistent` (written to
  1064. disk).
  1065. .. _conf-broker-settings:
  1066. Broker Settings
  1067. ---------------
  1068. .. setting:: broker_url
  1069. ``broker_url``
  1070. ~~~~~~~~~~~~~~
  1071. Default: ``"amqp://"``
  1072. Default broker URL. This must be a URL in the form of::
  1073. transport://userid:password@hostname:port/virtual_host
  1074. Only the scheme part (``transport://``) is required, the rest
  1075. is optional, and defaults to the specific transports default values.
  1076. The transport part is the broker implementation to use, and the
  1077. default is ``amqp``, (uses ``librabbitmq`` if installed or falls back to
  1078. ``pyamqp``). There are also other choices available, including;
  1079. ``redis://``, ``sqs://``, and ``qpid://``.
  1080. The scheme can also be a fully qualified path to your own transport
  1081. implementation::
  1082. broker_url = 'proj.transports.MyTransport://localhost'
  1083. More than one broker URL, of the same transport, can also be specified.
  1084. The broker URLs can be passed in as a single string that's semicolon delimited::
  1085. broker_url = 'transport://userid:password@hostname:port//;transport://userid:password@hostname:port//'
  1086. Or as a list::
  1087. broker_url = [
  1088. 'transport://userid:password@localhost:port//',
  1089. 'transport://userid:password@hostname:port//'
  1090. ]
  1091. The brokers will then be used in the :setting:`broker_failover_strategy`.
  1092. See :ref:`kombu:connection-urls` in the Kombu documentation for more
  1093. information.
  1094. .. setting:: broker_read_url
  1095. .. setting:: broker_write_url
  1096. ``broker_read_url`` / ``broker_write_url``
  1097. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1098. Default: Taken from :setting:`broker_url`.
  1099. These settings can be configured, instead of :setting:`broker_url` to specify
  1100. different connection parameters for broker connections used for consuming and
  1101. producing.
  1102. Example::
  1103. broker_read_url = 'amqp://user:pass@broker.example.com:56721'
  1104. broker_write_url = 'amqp://user:pass@broker.example.com:56722'
  1105. Both options can also be specified as a list for failover alternates, see
  1106. :setting:`broker_url` for more information.
  1107. .. setting:: broker_failover_strategy
  1108. ``broker_failover_strategy``
  1109. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1110. Default: ``"round-robin"``.
  1111. Default failover strategy for the broker Connection object. If supplied,
  1112. may map to a key in 'kombu.connection.failover_strategies', or be a reference
  1113. to any method that yields a single item from a supplied list.
  1114. Example::
  1115. # Random failover strategy
  1116. def random_failover_strategy(servers):
  1117. it = list(servers) # don't modify callers list
  1118. shuffle = random.shuffle
  1119. for _ in repeat(None):
  1120. shuffle(it)
  1121. yield it[0]
  1122. broker_failover_strategy = random_failover_strategy
  1123. .. setting:: broker_heartbeat
  1124. ``broker_heartbeat``
  1125. ~~~~~~~~~~~~~~~~~~~~
  1126. :transports supported: ``pyamqp``
  1127. Default: ``120.0`` (negotiated by server).
  1128. Note: This value is only used by the worker, clients do not use
  1129. a heartbeat at the moment.
  1130. It's not always possible to detect connection loss in a timely
  1131. manner using TCP/IP alone, so AMQP defines something called heartbeats
  1132. that's is used both by the client and the broker to detect if
  1133. a connection was closed.
  1134. If the heartbeat value is 10 seconds, then
  1135. the heartbeat will be monitored at the interval specified
  1136. by the :setting:`broker_heartbeat_checkrate` setting (by default
  1137. this is set to double the rate of the heartbeat value,
  1138. so for the 10 seconds, the heartbeat is checked every 5 seconds).
  1139. .. setting:: broker_heartbeat_checkrate
  1140. ``broker_heartbeat_checkrate``
  1141. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1142. :transports supported: ``pyamqp``
  1143. Default: 2.0.
  1144. At intervals the worker will monitor that the broker hasn't missed
  1145. too many heartbeats. The rate at which this is checked is calculated
  1146. by dividing the :setting:`broker_heartbeat` value with this value,
  1147. so if the heartbeat is 10.0 and the rate is the default 2.0, the check
  1148. will be performed every 5 seconds (twice the heartbeat sending rate).
  1149. .. setting:: broker_use_ssl
  1150. ``broker_use_ssl``
  1151. ~~~~~~~~~~~~~~~~~~
  1152. :transports supported: ``pyamqp``, ``redis``
  1153. Default: Disabled.
  1154. Toggles SSL usage on broker connection and SSL settings.
  1155. The valid values for this option vary by transport.
  1156. ``pyamqp``
  1157. __________
  1158. If ``True`` the connection will use SSL with default SSL settings.
  1159. If set to a dict, will configure SSL connection according to the specified
  1160. policy. The format used is Python's :func:`ssl.wrap_socket` options.
  1161. Note that SSL socket is generally served on a separate port by the broker.
  1162. Example providing a client cert and validating the server cert against a custom
  1163. certificate authority:
  1164. .. code-block:: python
  1165. import ssl
  1166. broker_use_ssl = {
  1167. 'keyfile': '/var/ssl/private/worker-key.pem',
  1168. 'certfile': '/var/ssl/amqp-server-cert.pem',
  1169. 'ca_certs': '/var/ssl/myca.pem',
  1170. 'cert_reqs': ssl.CERT_REQUIRED
  1171. }
  1172. .. warning::
  1173. Be careful using ``broker_use_ssl=True``. It's possible that your default
  1174. configuration won't validate the server cert at all. Please read Python
  1175. `ssl module security
  1176. considerations <https://docs.python.org/3/library/ssl.html#ssl-security>`_.
  1177. ``redis``
  1178. _________
  1179. The setting must be a dict the keys:
  1180. * ``ssl_cert_reqs`` (required): one of the ``SSLContext.verify_mode`` values:
  1181. * ``ssl.CERT_NONE``
  1182. * ``ssl.CERT_OPTIONAL``
  1183. * ``ssl.CERT_REQUIRED``
  1184. * ``ssl_ca_certs`` (optional): path to the CA certificate
  1185. * ``ssl_certfile`` (optional): path to the client certificate
  1186. * ``ssl_keyfile`` (optional): path to the client key
  1187. .. setting:: broker_pool_limit
  1188. ``broker_pool_limit``
  1189. ~~~~~~~~~~~~~~~~~~~~~
  1190. .. versionadded:: 2.3
  1191. Default: 10.
  1192. The maximum number of connections that can be open in the connection pool.
  1193. The pool is enabled by default since version 2.5, with a default limit of ten
  1194. connections. This number can be tweaked depending on the number of
  1195. threads/green-threads (eventlet/gevent) using a connection. For example
  1196. running eventlet with 1000 greenlets that use a connection to the broker,
  1197. contention can arise and you should consider increasing the limit.
  1198. If set to :const:`None` or 0 the connection pool will be disabled and
  1199. connections will be established and closed for every use.
  1200. .. setting:: broker_connection_timeout
  1201. ``broker_connection_timeout``
  1202. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1203. Default: 4.0.
  1204. The default timeout in seconds before we give up establishing a connection
  1205. to the AMQP server. This setting is disabled when using
  1206. gevent.
  1207. .. setting:: broker_connection_retry
  1208. ``broker_connection_retry``
  1209. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1210. Default: Enabled.
  1211. Automatically try to re-establish the connection to the AMQP broker if lost.
  1212. The time between retries is increased for each retry, and is
  1213. not exhausted before :setting:`broker_connection_max_retries` is
  1214. exceeded.
  1215. .. setting:: broker_connection_max_retries
  1216. ``broker_connection_max_retries``
  1217. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1218. Default: 100.
  1219. Maximum number of retries before we give up re-establishing a connection
  1220. to the AMQP broker.
  1221. If this is set to :const:`0` or :const:`None`, we'll retry forever.
  1222. .. setting:: broker_login_method
  1223. ``broker_login_method``
  1224. ~~~~~~~~~~~~~~~~~~~~~~~
  1225. Default: ``"AMQPLAIN"``.
  1226. Set custom amqp login method.
  1227. .. setting:: broker_transport_options
  1228. ``broker_transport_options``
  1229. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1230. .. versionadded:: 2.2
  1231. Default: ``{}`` (empty mapping).
  1232. A dict of additional options passed to the underlying transport.
  1233. See your transport user manual for supported options (if any).
  1234. Example setting the visibility timeout (supported by Redis and SQS
  1235. transports):
  1236. .. code-block:: python
  1237. broker_transport_options = {'visibility_timeout': 18000} # 5 hours
  1238. .. _conf-worker:
  1239. Worker
  1240. ------
  1241. .. setting:: imports
  1242. ``imports``
  1243. ~~~~~~~~~~~
  1244. Default: ``[]`` (empty list).
  1245. A sequence of modules to import when the worker starts.
  1246. This is used to specify the task modules to import, but also
  1247. to import signal handlers and additional remote control commands, etc.
  1248. The modules will be imported in the original order.
  1249. .. setting:: include
  1250. ``include``
  1251. ~~~~~~~~~~~
  1252. Default: ``[]`` (empty list).
  1253. Exact same semantics as :setting:`imports`, but can be used as a means
  1254. to have different import categories.
  1255. The modules in this setting are imported after the modules in
  1256. :setting:`imports`.
  1257. .. _conf-concurrency:
  1258. .. setting:: worker_concurrency
  1259. ``worker_concurrency``
  1260. ~~~~~~~~~~~~~~~~~~~~~~
  1261. Default: Number of CPU cores.
  1262. The number of concurrent worker processes/threads/green threads executing
  1263. tasks.
  1264. If you're doing mostly I/O you can have more processes,
  1265. but if mostly CPU-bound, try to keep it close to the
  1266. number of CPUs on your machine. If not set, the number of CPUs/cores
  1267. on the host will be used.
  1268. .. setting:: worker_prefetch_multiplier
  1269. ``worker_prefetch_multiplier``
  1270. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1271. Default: 4.
  1272. How many messages to prefetch at a time multiplied by the number of
  1273. concurrent processes. The default is 4 (four messages for each
  1274. process). The default setting is usually a good choice, however -- if you
  1275. have very long running tasks waiting in the queue and you have to start the
  1276. workers, note that the first worker to start will receive four times the
  1277. number of messages initially. Thus the tasks may not be fairly distributed
  1278. to the workers.
  1279. To disable prefetching, set :setting:`worker_prefetch_multiplier` to 1.
  1280. Changing that setting to 0 will allow the worker to keep consuming
  1281. as many messages as it wants.
  1282. For more on prefetching, read :ref:`optimizing-prefetch-limit`
  1283. .. note::
  1284. Tasks with ETA/countdown aren't affected by prefetch limits.
  1285. .. setting:: worker_lost_wait
  1286. ``worker_lost_wait``
  1287. ~~~~~~~~~~~~~~~~~~~~
  1288. Default: 10.0 seconds.
  1289. In some cases a worker may be killed without proper cleanup,
  1290. and the worker may have published a result before terminating.
  1291. This value specifies how long we wait for any missing results before
  1292. raising a :exc:`@WorkerLostError` exception.
  1293. .. setting:: worker_max_tasks_per_child
  1294. ``worker_max_tasks_per_child``
  1295. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1296. Maximum number of tasks a pool worker process can execute before
  1297. it's replaced with a new one. Default is no limit.
  1298. .. setting:: worker_max_memory_per_child
  1299. ``worker_max_memory_per_child``
  1300. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1301. Default: No limit.
  1302. Type: int (kilobytes)
  1303. Maximum amount of resident memory, in kilobytes, that may be consumed by a
  1304. worker before it will be replaced by a new worker. If a single
  1305. task causes a worker to exceed this limit, the task will be
  1306. completed, and the worker will be replaced afterwards.
  1307. Example:
  1308. .. code-block:: python
  1309. worker_max_memory_per_child = 12000 # 12MB
  1310. .. setting:: worker_disable_rate_limits
  1311. ``worker_disable_rate_limits``
  1312. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1313. Default: Disabled (rate limits enabled).
  1314. Disable all rate limits, even if tasks has explicit rate limits set.
  1315. .. setting:: worker_state_db
  1316. ``worker_state_db``
  1317. ~~~~~~~~~~~~~~~~~~~
  1318. Default: :const:`None`.
  1319. Name of the file used to stores persistent worker state (like revoked tasks).
  1320. Can be a relative or absolute path, but be aware that the suffix `.db`
  1321. may be appended to the file name (depending on Python version).
  1322. Can also be set via the :option:`celery worker --statedb` argument.
  1323. .. setting:: worker_timer_precision
  1324. ``worker_timer_precision``
  1325. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1326. Default: 1.0 seconds.
  1327. Set the maximum time in seconds that the ETA scheduler can sleep between
  1328. rechecking the schedule.
  1329. Setting this value to 1 second means the schedulers precision will
  1330. be 1 second. If you need near millisecond precision you can set this to 0.1.
  1331. .. setting:: worker_enable_remote_control
  1332. ``worker_enable_remote_control``
  1333. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1334. Default: Enabled by default.
  1335. Specify if remote control of the workers is enabled.
  1336. .. _conf-events:
  1337. Events
  1338. ------
  1339. .. setting:: worker_send_task_events
  1340. ``worker_send_task_events``
  1341. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1342. Default: Disabled by default.
  1343. Send task-related events so that tasks can be monitored using tools like
  1344. `flower`. Sets the default value for the workers
  1345. :option:`-E <celery worker -E>` argument.
  1346. .. setting:: task_send_sent_event
  1347. ``task_send_sent_event``
  1348. ~~~~~~~~~~~~~~~~~~~~~~~~
  1349. .. versionadded:: 2.2
  1350. Default: Disabled by default.
  1351. If enabled, a :event:`task-sent` event will be sent for every task so tasks can be
  1352. tracked before they're consumed by a worker.
  1353. .. setting:: event_queue_ttl
  1354. ``event_queue_ttl``
  1355. ~~~~~~~~~~~~~~~~~~~
  1356. :transports supported: ``amqp``
  1357. Default: 5.0 seconds.
  1358. Message expiry time in seconds (int/float) for when messages sent to a monitor clients
  1359. event queue is deleted (``x-message-ttl``)
  1360. For example, if this value is set to 10 then a message delivered to this queue
  1361. will be deleted after 10 seconds.
  1362. .. setting:: event_queue_expires
  1363. ``event_queue_expires``
  1364. ~~~~~~~~~~~~~~~~~~~~~~~
  1365. :transports supported: ``amqp``
  1366. Default: 60.0 seconds.
  1367. Expiry time in seconds (int/float) for when after a monitor clients
  1368. event queue will be deleted (``x-expires``).
  1369. .. setting:: event_queue_prefix
  1370. ``event_queue_prefix``
  1371. ~~~~~~~~~~~~~~~~~~~~~~
  1372. Default: ``"celeryev"``.
  1373. The prefix to use for event receiver queue names.
  1374. .. setting:: event_serializer
  1375. ``event_serializer``
  1376. ~~~~~~~~~~~~~~~~~~~~
  1377. Default: ``"json"``.
  1378. Message serialization format used when sending event messages.
  1379. .. seealso::
  1380. :ref:`calling-serializers`.
  1381. .. _conf-control:
  1382. Remote Control Commands
  1383. -----------------------
  1384. .. note::
  1385. To disable remote control commands see
  1386. the :setting:`worker_enable_remote_control` setting.
  1387. .. setting:: control_queue_ttl
  1388. ``control_queue_ttl``
  1389. ~~~~~~~~~~~~~~~~~~~~~
  1390. Default: 300.0
  1391. Time in seconds, before a message in a remote control command queue
  1392. will expire.
  1393. If using the default of 300 seconds, this means that if a remote control
  1394. command is sent and no worker picks it up within 300 seconds, the command
  1395. is discarded.
  1396. This setting also applies to remote control reply queues.
  1397. .. setting:: control_queue_expires
  1398. ``control_queue_expires``
  1399. ~~~~~~~~~~~~~~~~~~~~~~~~~
  1400. Default: 10.0
  1401. Time in seconds, before an unused remote control command queue is deleted
  1402. from the broker.
  1403. This setting also applies to remote control reply queues.
  1404. .. _conf-logging:
  1405. Logging
  1406. -------
  1407. .. setting:: worker_hijack_root_logger
  1408. ``worker_hijack_root_logger``
  1409. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1410. .. versionadded:: 2.2
  1411. Default: Enabled by default (hijack root logger).
  1412. By default any previously configured handlers on the root logger will be
  1413. removed. If you want to customize your own logging handlers, then you
  1414. can disable this behavior by setting
  1415. `worker_hijack_root_logger = False`.
  1416. .. note::
  1417. Logging can also be customized by connecting to the
  1418. :signal:`celery.signals.setup_logging` signal.
  1419. .. setting:: worker_log_color
  1420. ``worker_log_color``
  1421. ~~~~~~~~~~~~~~~~~~~~
  1422. Default: Enabled if app is logging to a terminal.
  1423. Enables/disables colors in logging output by the Celery apps.
  1424. .. setting:: worker_log_format
  1425. ``worker_log_format``
  1426. ~~~~~~~~~~~~~~~~~~~~~
  1427. Default:
  1428. .. code-block:: text
  1429. "[%(asctime)s: %(levelname)s/%(processName)s] %(message)s"
  1430. The format to use for log messages.
  1431. See the Python :mod:`logging` module for more information about log
  1432. formats.
  1433. .. setting:: worker_task_log_format
  1434. ``worker_task_log_format``
  1435. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1436. Default:
  1437. .. code-block:: text
  1438. "[%(asctime)s: %(levelname)s/%(processName)s]
  1439. [%(task_name)s(%(task_id)s)] %(message)s"
  1440. The format to use for log messages logged in tasks.
  1441. See the Python :mod:`logging` module for more information about log
  1442. formats.
  1443. .. setting:: worker_redirect_stdouts
  1444. ``worker_redirect_stdouts``
  1445. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1446. Default: Enabled by default.
  1447. If enabled `stdout` and `stderr` will be redirected
  1448. to the current logger.
  1449. Used by :program:`celery worker` and :program:`celery beat`.
  1450. .. setting:: worker_redirect_stdouts_level
  1451. ``worker_redirect_stdouts_level``
  1452. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1453. Default: :const:`WARNING`.
  1454. The log level output to `stdout` and `stderr` is logged as.
  1455. Can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
  1456. :const:`ERROR`, or :const:`CRITICAL`.
  1457. .. _conf-security:
  1458. Security
  1459. --------
  1460. .. setting:: security_key
  1461. ``security_key``
  1462. ~~~~~~~~~~~~~~~~
  1463. Default: :const:`None`.
  1464. .. versionadded:: 2.5
  1465. The relative or absolute path to a file containing the private key
  1466. used to sign messages when :ref:`message-signing` is used.
  1467. .. setting:: security_certificate
  1468. ``security_certificate``
  1469. ~~~~~~~~~~~~~~~~~~~~~~~~
  1470. Default: :const:`None`.
  1471. .. versionadded:: 2.5
  1472. The relative or absolute path to an X.509 certificate file
  1473. used to sign messages when :ref:`message-signing` is used.
  1474. .. setting:: security_cert_store
  1475. ``security_cert_store``
  1476. ~~~~~~~~~~~~~~~~~~~~~~~
  1477. Default: :const:`None`.
  1478. .. versionadded:: 2.5
  1479. The directory containing X.509 certificates used for
  1480. :ref:`message-signing`. Can be a glob with wild-cards,
  1481. (for example :file:`/etc/certs/*.pem`).
  1482. .. _conf-custom-components:
  1483. Custom Component Classes (advanced)
  1484. -----------------------------------
  1485. .. setting:: worker_pool
  1486. ``worker_pool``
  1487. ~~~~~~~~~~~~~~~
  1488. Default: ``"prefork"`` (``celery.concurrency.prefork:TaskPool``).
  1489. Name of the pool class used by the worker.
  1490. .. admonition:: Eventlet/Gevent
  1491. Never use this option to select the eventlet or gevent pool.
  1492. You must use the :option:`-P <celery worker -P>` option to
  1493. :program:`celery worker` instead, to ensure the monkey patches
  1494. aren't applied too late, causing things to break in strange ways.
  1495. .. setting:: worker_pool_restarts
  1496. ``worker_pool_restarts``
  1497. ~~~~~~~~~~~~~~~~~~~~~~~~
  1498. Default: Disabled by default.
  1499. If enabled the worker pool can be restarted using the
  1500. :control:`pool_restart` remote control command.
  1501. .. setting:: worker_autoscaler
  1502. ``worker_autoscaler``
  1503. ~~~~~~~~~~~~~~~~~~~~~
  1504. .. versionadded:: 2.2
  1505. Default: ``"celery.worker.autoscale:Autoscaler"``.
  1506. Name of the autoscaler class to use.
  1507. .. setting:: worker_consumer
  1508. ``worker_consumer``
  1509. ~~~~~~~~~~~~~~~~~~~
  1510. Default: ``"celery.worker.consumer:Consumer"``.
  1511. Name of the consumer class used by the worker.
  1512. .. setting:: worker_timer
  1513. ``worker_timer``
  1514. ~~~~~~~~~~~~~~~~
  1515. Default: ``"kombu.asynchronous.hub.timer:Timer"``.
  1516. Name of the ETA scheduler class used by the worker.
  1517. Default is or set by the pool implementation.
  1518. .. _conf-celerybeat:
  1519. Beat Settings (:program:`celery beat`)
  1520. --------------------------------------
  1521. .. setting:: beat_schedule
  1522. ``beat_schedule``
  1523. ~~~~~~~~~~~~~~~~~
  1524. Default: ``{}`` (empty mapping).
  1525. The periodic task schedule used by :mod:`~celery.bin.beat`.
  1526. See :ref:`beat-entries`.
  1527. .. setting:: beat_scheduler
  1528. ``beat_scheduler``
  1529. ~~~~~~~~~~~~~~~~~~
  1530. Default: ``"celery.beat:PersistentScheduler"``.
  1531. The default scheduler class. May be set to
  1532. ``"django_celery_beat.schedulers:DatabaseScheduler"`` for instance,
  1533. if used alongside `django-celery-beat` extension.
  1534. Can also be set via the :option:`celery beat -S` argument.
  1535. .. setting:: beat_schedule_filename
  1536. ``beat_schedule_filename``
  1537. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1538. Default: ``"celerybeat-schedule"``.
  1539. Name of the file used by `PersistentScheduler` to store the last run times
  1540. of periodic tasks. Can be a relative or absolute path, but be aware that the
  1541. suffix `.db` may be appended to the file name (depending on Python version).
  1542. Can also be set via the :option:`celery beat --schedule` argument.
  1543. .. setting:: beat_sync_every
  1544. ``beat_sync_every``
  1545. ~~~~~~~~~~~~~~~~~~~
  1546. Default: 0.
  1547. The number of periodic tasks that can be called before another database sync
  1548. is issued.
  1549. A value of 0 (default) means sync based on timing - default of 3 minutes as determined by
  1550. scheduler.sync_every. If set to 1, beat will call sync after every task
  1551. message sent.
  1552. .. setting:: beat_max_loop_interval
  1553. ``beat_max_loop_interval``
  1554. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1555. Default: 0.
  1556. The maximum number of seconds :mod:`~celery.bin.beat` can sleep
  1557. between checking the schedule.
  1558. The default for this value is scheduler specific.
  1559. For the default Celery beat scheduler the value is 300 (5 minutes),
  1560. but for the :pypi:`django-celery-beat` database scheduler it's 5 seconds
  1561. because the schedule may be changed externally, and so it must take
  1562. changes to the schedule into account.
  1563. Also when running Celery beat embedded (:option:`-B <celery worker -B>`)
  1564. on Jython as a thread the max interval is overridden and set to 1 so
  1565. that it's possible to shut down in a timely manner.