configuration.rst 63 KB

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