configuration.rst 62 KB

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