configuration.rst 67 KB

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