configuration.rst 59 KB

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