configuration.rst 63 KB

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