configuration.rst 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137
  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. * ``consul``
  383. Use the `Consul`_ K/V store to store the results
  384. See :ref:`conf-consul-result-backend`.
  385. .. warning:
  386. While the AMQP result backend is very efficient, you must make sure
  387. you only receive the same result once. See :doc:`userguide/calling`).
  388. .. _`SQLAlchemy`: http://sqlalchemy.org
  389. .. _`Memcached`: http://memcached.org
  390. .. _`Redis`: http://redis.io
  391. .. _`Cassandra`: http://cassandra.apache.org/
  392. .. _`Elasticsearch`: https://aws.amazon.com/elasticsearch-service/
  393. .. _`IronCache`: http://www.iron.io/cache
  394. .. _`CouchDB`: http://www.couchdb.com/
  395. .. _`Couchbase`: http://www.couchbase.com/
  396. .. _`Consul`: http://consul.io/
  397. .. setting:: result_serializer
  398. ``result_serializer``
  399. ~~~~~~~~~~~~~~~~~~~~~
  400. Result serialization format. Default is ``pickle``. See
  401. :ref:`calling-serializers` for information about supported
  402. serialization formats.
  403. .. setting:: result_compression
  404. ``result_compression``
  405. ~~~~~~~~~~~~~~~~~~~~~~
  406. Optional compression method used for task results.
  407. Supports the same options as the :setting:`task_serializer` setting.
  408. Default is no compression.
  409. .. setting:: result_expires
  410. ``result_expires``
  411. ~~~~~~~~~~~~~~~~~~
  412. Time (in seconds, or a :class:`~datetime.timedelta` object) for when after
  413. stored task tombstones will be deleted.
  414. A built-in periodic task will delete the results after this time
  415. (``celery.backend_cleanup``), assuming that ``celery beat`` is
  416. enabled. The task runs daily at 4am.
  417. A value of :const:`None` or 0 means results will never expire (depending
  418. on backend specifications).
  419. Default is to expire after 1 day.
  420. .. note::
  421. For the moment this only works with the AMQP, database, cache,
  422. and Redis result backends.
  423. When using the database backend, `celery beat` must be
  424. running for the results to be expired.
  425. .. setting:: result_cache_max
  426. ``result_cache_max``
  427. ~~~~~~~~~~~~~~~~~~~~
  428. Enables client caching of results, which can be useful for the old deprecated
  429. 'amqp' backend where the result is unavailable as soon as one result instance
  430. consumes it.
  431. This is the total number of results to cache before older results are evicted.
  432. A value of 0 or None means no limit, and a value of :const:`-1`
  433. will disable the cache.
  434. Disabled by default.
  435. .. _conf-database-result-backend:
  436. Database backend settings
  437. -------------------------
  438. Database URL Examples
  439. ~~~~~~~~~~~~~~~~~~~~~
  440. To use the database backend you have to configure the
  441. :setting:`result_backend` setting with a connection URL and the ``db+``
  442. prefix:
  443. .. code-block:: python
  444. result_backend = 'db+scheme://user:password@host:port/dbname'
  445. Examples::
  446. # sqlite (filename)
  447. result_backend = 'db+sqlite:///results.sqlite'
  448. # mysql
  449. result_backend = 'db+mysql://scott:tiger@localhost/foo'
  450. # postgresql
  451. result_backend = 'db+postgresql://scott:tiger@localhost/mydatabase'
  452. # oracle
  453. result_backend = 'db+oracle://scott:tiger@127.0.0.1:1521/sidname'
  454. .. code-block:: python
  455. Please see `Supported Databases`_ for a table of supported databases,
  456. and `Connection String`_ for more information about connection
  457. strings (which is the part of the URI that comes after the ``db+`` prefix).
  458. .. _`Supported Databases`:
  459. http://www.sqlalchemy.org/docs/core/engines.html#supported-databases
  460. .. _`Connection String`:
  461. http://www.sqlalchemy.org/docs/core/engines.html#database-urls
  462. .. setting:: sqlalchemy_dburi
  463. ``sqlalchemy_dburi``
  464. ~~~~~~~~~~~~~~~~~~~~
  465. This setting is no longer used as it's now possible to specify
  466. the database URL directly in the :setting:`result_backend` setting.
  467. .. setting:: sqlalchemy_engine_options
  468. ``sqlalchemy_engine_options``
  469. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  470. To specify additional SQLAlchemy database engine options you can use
  471. the :setting:`sqlalchmey_engine_options` setting::
  472. # echo enables verbose logging from SQLAlchemy.
  473. app.conf.sqlalchemy_engine_options = {'echo': True}
  474. .. setting:: sqlalchemy_short_lived_sessions
  475. ``sqlalchemy_short_lived_sessions``
  476. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  477. Short lived sessions are disabled by default. If enabled they can drastically reduce
  478. performance, especially on systems processing lots of tasks. This option is useful
  479. on low-traffic workers that experience errors as a result of cached database connections
  480. going stale through inactivity. For example, intermittent errors like
  481. `(OperationalError) (2006, 'MySQL server has gone away')` can be fixed by enabling
  482. short lived sessions. This option only affects the database backend.
  483. .. setting:: sqlalchemy_table_names
  484. ``sqlalchemy_table_names``
  485. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  486. When SQLAlchemy is configured as the result backend, Celery automatically
  487. creates two tables to store result meta-data for tasks. This setting allows
  488. you to customize the table names:
  489. .. code-block:: python
  490. # use custom table names for the database result backend.
  491. sqlalchemy_table_names = {
  492. 'task': 'myapp_taskmeta',
  493. 'group': 'myapp_groupmeta',
  494. }
  495. .. _conf-rpc-result-backend:
  496. RPC backend settings
  497. --------------------
  498. .. setting:: result_exchange
  499. ``result_exchange``
  500. ~~~~~~~~~~~~~~~~~~~
  501. Name of the exchange to publish results in. Default is `celeryresults`.
  502. .. setting:: result_exchange_type
  503. ``result_exchange_type``
  504. ~~~~~~~~~~~~~~~~~~~~~~~~
  505. The exchange type of the result exchange. Default is to use a `direct`
  506. exchange.
  507. .. setting:: result_persistent
  508. ``result_persistent``
  509. ~~~~~~~~~~~~~~~~~~~~~
  510. If set to :const:`True`, result messages will be persistent. This means the
  511. messages will not be lost after a broker restart. The default is for the
  512. results to be transient.
  513. Example configuration
  514. ~~~~~~~~~~~~~~~~~~~~~
  515. .. code-block:: python
  516. result_backend = 'rpc://'
  517. result_persistent = False
  518. .. _conf-cache-result-backend:
  519. Cache backend settings
  520. ----------------------
  521. .. note::
  522. The cache backend supports the :pypi:`pylibmc` and `python-memcached`
  523. libraries. The latter is used only if :pypi:`pylibmc` is not installed.
  524. Using a single Memcached server:
  525. .. code-block:: python
  526. result_backend = 'cache+memcached://127.0.0.1:11211/'
  527. Using multiple Memcached servers:
  528. .. code-block:: python
  529. result_backend = """
  530. cache+memcached://172.19.26.240:11211;172.19.26.242:11211/
  531. """.strip()
  532. The "memory" backend stores the cache in memory only:
  533. .. code-block:: python
  534. result_backend = 'cache'
  535. cache_backend = 'memory'
  536. .. setting:: cache_backend_options
  537. ``cache_backend_options``
  538. ~~~~~~~~~~~~~~~~~~~~~~~~~
  539. You can set :pypi:`pylibmc` options using the :setting:`cache_backend_options`
  540. setting:
  541. .. code-block:: python
  542. cache_backend_options = {
  543. 'binary': True,
  544. 'behaviors': {'tcp_nodelay': True},
  545. }
  546. .. setting:: cache_backend
  547. ``cache_backend``
  548. ~~~~~~~~~~~~~~~~~
  549. This setting is no longer used as it's now possible to specify
  550. the cache backend directly in the :setting:`result_backend` setting.
  551. .. _conf-redis-result-backend:
  552. Redis backend settings
  553. ----------------------
  554. Configuring the backend URL
  555. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  556. .. note::
  557. The Redis backend requires the :pypi:`redis` library:
  558. http://pypi.python.org/pypi/redis/
  559. To install the redis package use `pip` or `easy_install`:
  560. .. code-block:: console
  561. $ pip install redis
  562. This backend requires the :setting:`result_backend`
  563. setting to be set to a Redis URL::
  564. result_backend = 'redis://:password@host:port/db'
  565. For example::
  566. result_backend = 'redis://localhost/0'
  567. which is the same as::
  568. result_backend = 'redis://'
  569. The fields of the URL are defined as follows:
  570. #. ``password``
  571. Password used to connect to the database.
  572. #. ``host``
  573. Host name or IP address of the Redis server. e.g. `localhost`.
  574. #. ``port``
  575. Port to the Redis server. Default is 6379.
  576. #. ``db``
  577. Database number to use. Default is 0.
  578. The db can include an optional leading slash.
  579. .. setting:: redis_max_connections
  580. ``redis_max_connections``
  581. ~~~~~~~~~~~~~~~~~~~~~~~~~
  582. Maximum number of connections available in the Redis connection
  583. pool used for sending and retrieving results.
  584. .. setting:: redis_socket_timeout
  585. ``redis_socket_timeout``
  586. ~~~~~~~~~~~~~~~~~~~~~~~~
  587. Socket timeout for connections to Redis from the result backend
  588. in seconds (int/float)
  589. Default is 5 seconds.
  590. .. _conf-cassandra-result-backend:
  591. Cassandra backend settings
  592. --------------------------
  593. .. note::
  594. This Cassandra backend driver requires :pypi:`cassandra-driver`.
  595. https://pypi.python.org/pypi/cassandra-driver
  596. To install, use `pip` or `easy_install`:
  597. .. code-block:: console
  598. $ pip install cassandra-driver
  599. This backend requires the following configuration directives to be set.
  600. .. setting:: cassandra_servers
  601. ``cassandra_servers``
  602. ~~~~~~~~~~~~~~~~~~~~~
  603. List of ``host`` Cassandra servers. e.g.::
  604. cassandra_servers = ['localhost']
  605. .. setting:: cassandra_port
  606. ``cassandra_port``
  607. ~~~~~~~~~~~~~~~~~~
  608. Port to contact the Cassandra servers on. Default is 9042.
  609. .. setting:: cassandra_keyspace
  610. ``cassandra_keyspace``
  611. ~~~~~~~~~~~~~~~~~~~~~~
  612. The key-space in which to store the results. e.g.::
  613. cassandra_keyspace = 'tasks_keyspace'
  614. .. setting:: cassandra_table
  615. ``cassandra_table``
  616. ~~~~~~~~~~~~~~~~~~~
  617. The table (column family) in which to store the results. e.g.::
  618. cassandra_table = 'tasks'
  619. .. setting:: cassandra_read_consistency
  620. ``cassandra_read_consistency``
  621. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  622. The read consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``,
  623. ``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``.
  624. .. setting:: cassandra_write_consistency
  625. ``cassandra_write_consistency``
  626. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  627. The write consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``,
  628. ``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``.
  629. .. setting:: cassandra_entry_ttl
  630. ``cassandra_entry_ttl``
  631. ~~~~~~~~~~~~~~~~~~~~~~~
  632. Time-to-live for status entries. They will expire and be removed after that many seconds
  633. after adding. Default (None) means they will never expire.
  634. .. setting:: cassandra_auth_provider
  635. ``cassandra_auth_provider``
  636. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  637. AuthProvider class within ``cassandra.auth`` module to use. Values can be
  638. ``PlainTextAuthProvider`` or ``SaslAuthProvider``.
  639. .. setting:: cassandra_auth_kwargs
  640. ``cassandra_auth_kwargs``
  641. ~~~~~~~~~~~~~~~~~~~~~~~~~
  642. Named arguments to pass into the authentication provider. e.g.:
  643. .. code-block:: python
  644. cassandra_auth_kwargs = {
  645. username: 'cassandra',
  646. password: 'cassandra'
  647. }
  648. Example configuration
  649. ~~~~~~~~~~~~~~~~~~~~~
  650. .. code-block:: python
  651. cassandra_servers = ['localhost']
  652. cassandra_keyspace = 'celery'
  653. cassandra_table = 'tasks'
  654. cassandra_read_consistency = 'ONE'
  655. cassandra_write_consistency = 'ONE'
  656. cassandra_entry_ttl = 86400
  657. .. _conf-elasticsearch-result-backend:
  658. Elasticsearch backend settings
  659. ------------------------------
  660. To use `Elasticsearch`_ as the result backend you simply need to
  661. configure the :setting:`result_backend` setting with the correct URL.
  662. Example configuration
  663. ~~~~~~~~~~~~~~~~~~~~~
  664. .. code-block:: python
  665. result_backend = 'elasticsearch://example.com:9200/index_name/doc_type'
  666. .. _conf-riak-result-backend:
  667. Riak backend settings
  668. ---------------------
  669. .. note::
  670. The Riak backend requires the :pypi:`riak` library:
  671. http://pypi.python.org/pypi/riak/
  672. To install the :pypi:`riak` package use `pip` or `easy_install`:
  673. .. code-block:: console
  674. $ pip install riak
  675. This backend requires the :setting:`result_backend`
  676. setting to be set to a Riak URL::
  677. result_backend = 'riak://host:port/bucket'
  678. For example::
  679. result_backend = 'riak://localhost/celery
  680. which is the same as::
  681. result_backend = 'riak://'
  682. The fields of the URL are defined as follows:
  683. #. ``host``
  684. Host name or IP address of the Riak server. e.g. `'localhost'`.
  685. #. ``port``
  686. Port to the Riak server using the protobuf protocol. Default is 8087.
  687. #. ``bucket``
  688. Bucket name to use. Default is `celery`.
  689. The bucket needs to be a string with ASCII characters only.
  690. Alternatively, this backend can be configured with the following configuration directives.
  691. .. setting:: riak_backend_settings
  692. ``riak_backend_settings``
  693. ~~~~~~~~~~~~~~~~~~~~~~~~~
  694. This is a dict supporting the following keys:
  695. * ``host``
  696. The host name of the Riak server. Defaults to ``"localhost"``.
  697. * ``port``
  698. The port the Riak server is listening to. Defaults to 8087.
  699. * ``bucket``
  700. The bucket name to connect to. Defaults to "celery".
  701. * ``protocol``
  702. The protocol to use to connect to the Riak server. This is not configurable
  703. via :setting:`result_backend`
  704. .. _conf-ironcache-result-backend:
  705. IronCache backend settings
  706. --------------------------
  707. .. note::
  708. The IronCache backend requires the :pypi:`iron_celery` library:
  709. http://pypi.python.org/pypi/iron_celery
  710. To install the iron_celery package use `pip` or `easy_install`:
  711. .. code-block:: console
  712. $ pip install iron_celery
  713. IronCache is configured via the URL provided in :setting:`result_backend`, for example::
  714. result_backend = 'ironcache://project_id:token@'
  715. Or to change the cache name::
  716. ironcache:://project_id:token@/awesomecache
  717. For more information, see: https://github.com/iron-io/iron_celery
  718. .. _conf-couchbase-result-backend:
  719. Couchbase backend settings
  720. --------------------------
  721. .. note::
  722. The Couchbase backend requires the :pypi:`couchbase` library:
  723. https://pypi.python.org/pypi/couchbase
  724. To install the :pypi:`couchbase` package use `pip` or `easy_install`:
  725. .. code-block:: console
  726. $ pip install couchbase
  727. This backend can be configured via the :setting:`result_backend`
  728. set to a Couchbase URL:
  729. .. code-block:: python
  730. result_backend = 'couchbase://username:password@host:port/bucket'
  731. .. setting:: couchbase_backend_settings
  732. ``couchbase_backend_settings``
  733. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  734. This is a dict supporting the following keys:
  735. * ``host``
  736. Host name of the Couchbase server. Defaults to ``localhost``.
  737. * ``port``
  738. The port the Couchbase server is listening to. Defaults to ``8091``.
  739. * ``bucket``
  740. The default bucket the Couchbase server is writing to.
  741. Defaults to ``default``.
  742. * ``username``
  743. User name to authenticate to the Couchbase server as (optional).
  744. * ``password``
  745. Password to authenticate to the Couchbase server (optional).
  746. .. _conf-couchdb-result-backend:
  747. CouchDB backend settings
  748. ------------------------
  749. .. note::
  750. The CouchDB backend requires the :pypi:`pycouchdb` library:
  751. https://pypi.python.org/pypi/pycouchdb
  752. To install the Couchbase package use :command:`pip`, or :command:`easy_install`:
  753. .. code-block:: console
  754. $ pip install pycouchdb
  755. This backend can be configured via the :setting:`result_backend`
  756. set to a CouchDB URL::
  757. result_backend = 'couchdb://username:password@host:port/container'
  758. The URL is formed out of the following parts:
  759. * ``username``
  760. User name to authenticate to the CouchDB server as (optional).
  761. * ``password``
  762. Password to authenticate to the CouchDB server (optional).
  763. * ``host``
  764. Host name of the CouchDB server. Defaults to ``localhost``.
  765. * ``port``
  766. The port the CouchDB server is listening to. Defaults to ``8091``.
  767. * ``container``
  768. The default container the CouchDB server is writing to.
  769. Defaults to ``default``.
  770. .. _conf-filesystem-result-backend:
  771. File-system backend settings
  772. ----------------------------
  773. This backend can be configured using a file URL, for example::
  774. CELERY_RESULT_BACKEND = 'file:///var/celery/results'
  775. The configured directory needs to be shared and writable by all servers using
  776. the backend.
  777. If you are trying Celery on a single system you can simply use the backend
  778. without any further configuration. For larger clusters you could use NFS,
  779. `GlusterFS`_, CIFS, `HDFS`_ (using FUSE) or any other file-system.
  780. .. _`GlusterFS`: http://www.gluster.org/
  781. .. _`HDFS`: http://hadoop.apache.org/
  782. .. _conf-consul-result-backend:
  783. Consul K/V store backend settings
  784. ---------------------------------
  785. The Consul backend can be configured using a URL, for example:
  786. CELERY_RESULT_BACKEND = 'consul://localhost:8500/'
  787. The backend will storage results in the K/V store of Consul
  788. as individual keys.
  789. The backend supports auto expire of results using TTLs in Consul.
  790. .. _conf-messaging:
  791. Message Routing
  792. ---------------
  793. .. _conf-messaging-routing:
  794. .. setting:: task_queues
  795. ``task_queues``
  796. ~~~~~~~~~~~~~~~
  797. Most users will not want to specify this setting and should rather use
  798. the :ref:`automatic routing facilities <routing-automatic>`.
  799. If you really want to configure advanced routing, this setting should
  800. be a list of :class:`kombu.Queue` objects the worker will consume from.
  801. Note that workers can be overridden this setting via the
  802. :option:`-Q <celery worker -Q>` option, or individual queues from this
  803. list (by name) can be excluded using the :option:`-X <celery worker -X>`
  804. option.
  805. Also see :ref:`routing-basics` for more information.
  806. The default is a queue/exchange/binding key of ``celery``, with
  807. exchange type ``direct``.
  808. See also :setting:`task_routes`
  809. .. setting:: task_routes
  810. ``task_routes``
  811. ~~~~~~~~~~~~~~~
  812. A list of routers, or a single router used to route tasks to queues.
  813. When deciding the final destination of a task the routers are consulted
  814. in order.
  815. A router can be specified as either:
  816. * A router class instance.
  817. * A string which provides the path to a router class
  818. * A dict containing router specification:
  819. Will be converted to a :class:`celery.routes.MapRoute` instance.
  820. * A list of ``(pattern, route)`` tuples:
  821. Will be converted to a :class:`celery.routes.MapRoute` instance.
  822. Examples:
  823. .. code-block:: python
  824. task_routes = {
  825. 'celery.ping': 'default',
  826. 'mytasks.add': 'cpu-bound',
  827. 'feed.tasks.*': 'feeds', # <-- glob pattern
  828. re.compile(r'(image|video)\.tasks\..*'): 'media', # <-- regex
  829. 'video.encode': {
  830. 'queue': 'video',
  831. 'exchange': 'media'
  832. 'routing_key': 'media.video.encode',
  833. },
  834. }
  835. task_routes = ('myapp.tasks.Router', {'celery.ping': 'default})
  836. Where ``myapp.tasks.Router`` could be:
  837. .. code-block:: python
  838. class Router(object):
  839. def route_for_task(self, task, args=None, kwargs=None):
  840. if task == 'celery.ping':
  841. return {'queue': 'default'}
  842. ``route_for_task`` may return a string or a dict. A string then means
  843. it's a queue name in :setting:`task_queues`, a dict means it's a custom route.
  844. When sending tasks, the routers are consulted in order. The first
  845. router that doesn't return ``None`` is the route to use. The message options
  846. is then merged with the found route settings, where the routers settings
  847. have priority.
  848. Example if :func:`~celery.execute.apply_async` has these arguments:
  849. .. code-block:: python
  850. Task.apply_async(immediate=False, exchange='video',
  851. routing_key='video.compress')
  852. and a router returns:
  853. .. code-block:: python
  854. {'immediate': True, 'exchange': 'urgent'}
  855. the final message options will be:
  856. .. code-block:: python
  857. immediate=True, exchange='urgent', routing_key='video.compress'
  858. (and any default message options defined in the
  859. :class:`~celery.task.base.Task` class)
  860. Values defined in :setting:`task_routes` have precedence over values defined in
  861. :setting:`task_queues` when merging the two.
  862. With the follow settings:
  863. .. code-block:: python
  864. task_queues = {
  865. 'cpubound': {
  866. 'exchange': 'cpubound',
  867. 'routing_key': 'cpubound',
  868. },
  869. }
  870. task_routes = {
  871. 'tasks.add': {
  872. 'queue': 'cpubound',
  873. 'routing_key': 'tasks.add',
  874. 'serializer': 'json',
  875. },
  876. }
  877. The final routing options for ``tasks.add`` will become:
  878. .. code-block:: javascript
  879. {'exchange': 'cpubound',
  880. 'routing_key': 'tasks.add',
  881. 'serializer': 'json'}
  882. See :ref:`routers` for more examples.
  883. .. setting:: task_queue_ha_policy
  884. ``task_queue_ha_policy``
  885. ~~~~~~~~~~~~~~~~~~~~~~~~
  886. :brokers: RabbitMQ
  887. This will set the default HA policy for a queue, and the value
  888. can either be a string (usually ``all``):
  889. .. code-block:: python
  890. task_queue_ha_policy = 'all'
  891. Using 'all' will replicate the queue to all current nodes,
  892. Or you can give it a list of nodes to replicate to:
  893. .. code-block:: python
  894. task_queue_ha_policy = ['rabbit@host1', 'rabbit@host2']
  895. Using a list will implicitly set ``x-ha-policy`` to 'nodes' and
  896. ``x-ha-policy-params`` to the given list of nodes.
  897. See http://www.rabbitmq.com/ha.html for more information.
  898. .. setting:: task_queue_max_priority
  899. ``task_queue_max_priority``
  900. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  901. :brokers: RabbitMQ
  902. See :ref:`routing-options-rabbitmq-priorities`.
  903. .. setting:: worker_direct
  904. ``worker_direct``
  905. ~~~~~~~~~~~~~~~~~
  906. This option enables so that every worker has a dedicated queue,
  907. so that tasks can be routed to specific workers.
  908. The queue name for each worker is automatically generated based on
  909. the worker hostname and a ``.dq`` suffix, using the ``C.dq`` exchange.
  910. For example the queue name for the worker with node name ``w1@example.com``
  911. becomes::
  912. w1@example.com.dq
  913. Then you can route the task to the task by specifying the hostname
  914. as the routing key and the ``C.dq`` exchange::
  915. task_routes = {
  916. 'tasks.add': {'exchange': 'C.dq', 'routing_key': 'w1@example.com'}
  917. }
  918. .. setting:: task_create_missing_queues
  919. ``task_create_missing_queues``
  920. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  921. If enabled (default), any queues specified that are not defined in
  922. :setting:`task_queues` will be automatically created. See
  923. :ref:`routing-automatic`.
  924. .. setting:: task_default_queue
  925. ``task_default_queue``
  926. ~~~~~~~~~~~~~~~~~~~~~~
  927. The name of the default queue used by `.apply_async` if the message has
  928. no route or no custom queue has been specified.
  929. This queue must be listed in :setting:`task_queues`.
  930. If :setting:`task_queues` is not specified then it is automatically
  931. created containing one queue entry, where this name is used as the name of
  932. that queue.
  933. The default is: `celery`.
  934. .. seealso::
  935. :ref:`routing-changing-default-queue`
  936. .. setting:: task_default_exchange
  937. ``task_default_exchange``
  938. ~~~~~~~~~~~~~~~~~~~~~~~~~
  939. Name of the default exchange to use when no custom exchange is
  940. specified for a key in the :setting:`task_queues` setting.
  941. The default is: `celery`.
  942. .. setting:: task_default_exchange_type
  943. ``task_default_exchange_type``
  944. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  945. Default exchange type used when no custom exchange type is specified
  946. for a key in the :setting:`task_queues` setting.
  947. The default is: `direct`.
  948. .. setting:: task_default_routing_key
  949. ``task_default_routing_key``
  950. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  951. The default routing key used when no custom routing key
  952. is specified for a key in the :setting:`task_queues` setting.
  953. The default is: `celery`.
  954. .. setting:: task_default_delivery_mode
  955. ``task_default_delivery_mode``
  956. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  957. Can be `transient` or `persistent`. The default is to send
  958. persistent messages.
  959. .. _conf-broker-settings:
  960. Broker Settings
  961. ---------------
  962. .. setting:: broker_url
  963. ``broker_url``
  964. ~~~~~~~~~~~~~~
  965. Default broker URL. This must be a URL in the form of::
  966. transport://userid:password@hostname:port/virtual_host
  967. Only the scheme part (``transport://``) is required, the rest
  968. is optional, and defaults to the specific transports default values.
  969. The transport part is the broker implementation to use, and the
  970. default is ``amqp``, which uses ``librabbitmq`` by default or falls back to
  971. ``pyamqp`` if that is not installed. Also there are many other choices including
  972. ``redis``, ``beanstalk``, ``sqlalchemy``, ``django``, ``mongodb``,
  973. ``couchdb``.
  974. It can also be a fully qualified path to your own transport implementation.
  975. More than one broker URL, of the same transport, can also be specified.
  976. The broker URLs can be passed in as a single string that is semicolon delimited::
  977. broker_url = 'transport://userid:password@hostname:port//;transport://userid:password@hostname:port//'
  978. Or as a list::
  979. broker_url = [
  980. 'transport://userid:password@localhost:port//',
  981. 'transport://userid:password@hostname:port//'
  982. ]
  983. The brokers will then be used in the :setting:`broker_failover_strategy`.
  984. See :ref:`kombu:connection-urls` in the Kombu documentation for more
  985. information.
  986. .. setting:: broker_read_url
  987. .. setting:: broker_write_url
  988. ``broker_read_url`` / ``broker_write_url``
  989. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  990. These settings can be configured, instead of :setting:`broker_url` to specify
  991. different connection parameters for broker connections used for consuming and
  992. producing.
  993. Example::
  994. broker_read_url = 'amqp://user:pass@broker.example.com:56721'
  995. broker_write_url = 'amqp://user:pass@broker.example.com:56722'
  996. Both options can also be specified as a list for failover alternates, see
  997. :setting:`broker_url` for more information.
  998. .. setting:: broker_failover_strategy
  999. ``broker_failover_strategy``
  1000. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1001. Default failover strategy for the broker Connection object. If supplied,
  1002. may map to a key in 'kombu.connection.failover_strategies', or be a reference
  1003. to any method that yields a single item from a supplied list.
  1004. Example::
  1005. # Random failover strategy
  1006. def random_failover_strategy(servers):
  1007. it = list(it) # don't modify callers list
  1008. shuffle = random.shuffle
  1009. for _ in repeat(None):
  1010. shuffle(it)
  1011. yield it[0]
  1012. broker_failover_strategy = random_failover_strategy
  1013. .. setting:: broker_heartbeat
  1014. ``broker_heartbeat``
  1015. ~~~~~~~~~~~~~~~~~~~~
  1016. :transports supported: ``pyamqp``
  1017. It's not always possible to detect connection loss in a timely
  1018. manner using TCP/IP alone, so AMQP defines something called heartbeats
  1019. that's is used both by the client and the broker to detect if
  1020. a connection was closed.
  1021. Heartbeats are disabled by default.
  1022. If the heartbeat value is 10 seconds, then
  1023. the heartbeat will be monitored at the interval specified
  1024. by the :setting:`broker_heartbeat_checkrate` setting, which by default is
  1025. double the rate of the heartbeat value
  1026. (so for the default 10 seconds, the heartbeat is checked every 5 seconds).
  1027. .. setting:: broker_heartbeat_checkrate
  1028. ``broker_heartbeat_checkrate``
  1029. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1030. :transports supported: ``pyamqp``
  1031. At intervals the worker will monitor that the broker has not missed
  1032. too many heartbeats. The rate at which this is checked is calculated
  1033. by dividing the :setting:`broker_heartbeat` value with this value,
  1034. so if the heartbeat is 10.0 and the rate is the default 2.0, the check
  1035. will be performed every 5 seconds (twice the heartbeat sending rate).
  1036. .. setting:: broker_use_ssl
  1037. ``broker_use_ssl``
  1038. ~~~~~~~~~~~~~~~~~~
  1039. :transports supported: ``pyamqp``, ``redis``
  1040. Toggles SSL usage on broker connection and SSL settings.
  1041. If ``True`` the connection will use SSL with default SSL settings.
  1042. If set to a dict, will configure SSL connection according to the specified
  1043. policy. The format used is python `ssl.wrap_socket()
  1044. options <https://docs.python.org/3/library/ssl.html#ssl.wrap_socket>`_.
  1045. Default is ``False`` (no SSL).
  1046. Note that SSL socket is generally served on a separate port by the broker.
  1047. Example providing a client cert and validating the server cert against a custom
  1048. certificate authority:
  1049. .. code-block:: python
  1050. import ssl
  1051. broker_use_ssl = {
  1052. 'keyfile': '/var/ssl/private/worker-key.pem',
  1053. 'certfile': '/var/ssl/amqp-server-cert.pem',
  1054. 'ca_certs': '/var/ssl/myca.pem',
  1055. 'cert_reqs': ssl.CERT_REQUIRED
  1056. }
  1057. .. warning::
  1058. Be careful using ``broker_use_ssl=True``. It is possible that your default
  1059. configuration will not validate the server cert at all. Please read Python
  1060. `ssl module security
  1061. considerations <https://docs.python.org/3/library/ssl.html#ssl-security>`_.
  1062. .. setting:: broker_pool_limit
  1063. ``broker_pool_limit``
  1064. ~~~~~~~~~~~~~~~~~~~~~
  1065. .. versionadded:: 2.3
  1066. The maximum number of connections that can be open in the connection pool.
  1067. The pool is enabled by default since version 2.5, with a default limit of ten
  1068. connections. This number can be tweaked depending on the number of
  1069. threads/green-threads (eventlet/gevent) using a connection. For example
  1070. running eventlet with 1000 greenlets that use a connection to the broker,
  1071. contention can arise and you should consider increasing the limit.
  1072. If set to :const:`None` or 0 the connection pool will be disabled and
  1073. connections will be established and closed for every use.
  1074. Default (since 2.5) is to use a pool of 10 connections.
  1075. .. setting:: broker_connection_timeout
  1076. ``broker_connection_timeout``
  1077. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1078. The default timeout in seconds before we give up establishing a connection
  1079. to the AMQP server. Default is 4 seconds. This setting is disabled when using
  1080. gevent.
  1081. .. setting:: broker_connection_retry
  1082. ``broker_connection_retry``
  1083. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1084. Automatically try to re-establish the connection to the AMQP broker if lost.
  1085. The time between retries is increased for each retry, and is
  1086. not exhausted before :setting:`broker_connection_max_retries` is
  1087. exceeded.
  1088. This behavior is on by default.
  1089. .. setting:: broker_connection_max_retries
  1090. ``broker_connection_max_retries``
  1091. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1092. Maximum number of retries before we give up re-establishing a connection
  1093. to the AMQP broker.
  1094. If this is set to :const:`0` or :const:`None`, we will retry forever.
  1095. Default is 100 retries.
  1096. .. setting:: broker_login_method
  1097. ``broker_login_method``
  1098. ~~~~~~~~~~~~~~~~~~~~~~~
  1099. Set custom amqp login method, default is ``AMQPLAIN``.
  1100. .. setting:: broker_transport_options
  1101. ``broker_transport_options``
  1102. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1103. .. versionadded:: 2.2
  1104. A dict of additional options passed to the underlying transport.
  1105. See your transport user manual for supported options (if any).
  1106. Example setting the visibility timeout (supported by SQS
  1107. transports):
  1108. .. code-block:: python
  1109. broker_transport_options = {'visibility_timeout': 18000} # 5 hours
  1110. .. _conf-worker:
  1111. Worker
  1112. ------
  1113. .. setting:: imports
  1114. ``imports``
  1115. ~~~~~~~~~~~
  1116. A sequence of modules to import when the worker starts.
  1117. This is used to specify the task modules to import, but also
  1118. to import signal handlers and additional remote control commands, etc.
  1119. The modules will be imported in the original order.
  1120. .. setting:: include
  1121. ``include``
  1122. ~~~~~~~~~~~
  1123. Exact same semantics as :setting:`imports`, but can be used as a means
  1124. to have different import categories.
  1125. The modules in this setting are imported after the modules in
  1126. :setting:`imports`.
  1127. .. _conf-concurrency:
  1128. .. setting:: worker_concurrency
  1129. ``worker_concurrency``
  1130. ~~~~~~~~~~~~~~~~~~~~~~
  1131. The number of concurrent worker processes/threads/green threads executing
  1132. tasks.
  1133. If you're doing mostly I/O you can have more processes,
  1134. but if mostly CPU-bound, try to keep it close to the
  1135. number of CPUs on your machine. If not set, the number of CPUs/cores
  1136. on the host will be used.
  1137. Defaults to the number of available CPUs.
  1138. .. setting:: worker_prefetch_multiplier
  1139. ``worker_prefetch_multiplier``
  1140. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1141. How many messages to prefetch at a time multiplied by the number of
  1142. concurrent processes. The default is 4 (four messages for each
  1143. process). The default setting is usually a good choice, however -- if you
  1144. have very long running tasks waiting in the queue and you have to start the
  1145. workers, note that the first worker to start will receive four times the
  1146. number of messages initially. Thus the tasks may not be fairly distributed
  1147. to the workers.
  1148. To disable prefetching, set :setting:`worker_prefetch_multiplier` to 1.
  1149. Changing that setting to 0 will allow the worker to keep consuming
  1150. as many messages as it wants.
  1151. For more on prefetching, read :ref:`optimizing-prefetch-limit`
  1152. .. note::
  1153. Tasks with ETA/countdown are not affected by prefetch limits.
  1154. .. setting:: worker_lost_wait
  1155. ``worker_lost_wait``
  1156. ~~~~~~~~~~~~~~~~~~~~
  1157. In some cases a worker may be killed without proper cleanup,
  1158. and the worker may have published a result before terminating.
  1159. This value specifies how long we wait for any missing results before
  1160. raising a :exc:`@WorkerLostError` exception.
  1161. Default is 10.0
  1162. .. setting:: worker_max_tasks_per_child
  1163. ``worker_max_tasks_per_child``
  1164. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1165. Maximum number of tasks a pool worker process can execute before
  1166. it's replaced with a new one. Default is no limit.
  1167. .. setting:: worker_max_memory_per_child
  1168. ``worker_max_memory_per_child``
  1169. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1170. Maximum amount of resident memory that may be consumed by a
  1171. worker before it will be replaced by a new worker. If a single
  1172. task causes a worker to exceed this limit, the task will be
  1173. completed, and the worker will be replaced afterwards. Default:
  1174. no limit.
  1175. .. setting:: worker_disable_rate_limits
  1176. ``worker_disable_rate_limits``
  1177. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1178. Disable all rate limits, even if tasks has explicit rate limits set.
  1179. .. setting:: worker_state_db
  1180. ``worker_state_db``
  1181. ~~~~~~~~~~~~~~~~~~~
  1182. Name of the file used to stores persistent worker state (like revoked tasks).
  1183. Can be a relative or absolute path, but be aware that the suffix `.db`
  1184. may be appended to the file name (depending on Python version).
  1185. Can also be set via the :option:`celery worker --statedb` argument.
  1186. Not enabled by default.
  1187. .. setting:: worker_timer_precision
  1188. ``worker_timer_precision``
  1189. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1190. Set the maximum time in seconds that the ETA scheduler can sleep between
  1191. rechecking the schedule. Default is 1 second.
  1192. Setting this value to 1 second means the schedulers precision will
  1193. be 1 second. If you need near millisecond precision you can set this to 0.1.
  1194. .. setting:: worker_enable_remote_control
  1195. ``worker_enable_remote_control``
  1196. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1197. Specify if remote control of the workers is enabled.
  1198. Default is :const:`True`.
  1199. .. _conf-events:
  1200. Events
  1201. ------
  1202. .. setting:: worker_send_task_events
  1203. ``worker_send_task_events``
  1204. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1205. Send task-related events so that tasks can be monitored using tools like
  1206. `flower`. Sets the default value for the workers
  1207. :option:`-E <celery worker -E>` argument.
  1208. .. setting:: task_send_sent_event
  1209. ``task_send_sent_event``
  1210. ~~~~~~~~~~~~~~~~~~~~~~~~
  1211. .. versionadded:: 2.2
  1212. If enabled, a :event:`task-sent` event will be sent for every task so tasks can be
  1213. tracked before they are consumed by a worker.
  1214. Disabled by default.
  1215. .. setting:: event_queue_ttl
  1216. ``event_queue_ttl``
  1217. ~~~~~~~~~~~~~~~~~~~
  1218. :transports supported: ``amqp``
  1219. Message expiry time in seconds (int/float) for when messages sent to a monitor clients
  1220. event queue is deleted (``x-message-ttl``)
  1221. For example, if this value is set to 10 then a message delivered to this queue
  1222. will be deleted after 10 seconds.
  1223. Disabled by default.
  1224. .. setting:: event_queue_expires
  1225. ``event_queue_expires``
  1226. ~~~~~~~~~~~~~~~~~~~~~~~
  1227. :transports supported: ``amqp``
  1228. Expiry time in seconds (int/float) for when after a monitor clients
  1229. event queue will be deleted (``x-expires``).
  1230. Default is never, relying on the queue auto-delete setting.
  1231. .. setting:: event_queue_prefix
  1232. ``event_queue_prefix``
  1233. ~~~~~~~~~~~~~~~~~~~~~~
  1234. The prefix to use for event receiver queue names.
  1235. The default is ``celeryev``.
  1236. .. setting:: event_serializer
  1237. ``event_serializer``
  1238. ~~~~~~~~~~~~~~~~~~~~
  1239. Message serialization format used when sending event messages.
  1240. Default is ``json``. See :ref:`calling-serializers`.
  1241. .. _conf-logging:
  1242. Logging
  1243. -------
  1244. .. setting:: worker_hijack_root_logger
  1245. ``worker_hijack_root_logger``
  1246. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1247. .. versionadded:: 2.2
  1248. By default any previously configured handlers on the root logger will be
  1249. removed. If you want to customize your own logging handlers, then you
  1250. can disable this behavior by setting
  1251. `worker_hijack_root_logger = False`.
  1252. .. note::
  1253. Logging can also be customized by connecting to the
  1254. :signal:`celery.signals.setup_logging` signal.
  1255. .. setting:: worker_log_color
  1256. ``worker_log_color``
  1257. ~~~~~~~~~~~~~~~~~~~~
  1258. Enables/disables colors in logging output by the Celery apps.
  1259. By default colors are enabled if the app is logging to a real
  1260. terminal, and not a file.
  1261. .. setting:: worker_log_format
  1262. ``worker_log_format``
  1263. ~~~~~~~~~~~~~~~~~~~~~
  1264. The format to use for log messages.
  1265. Default is::
  1266. [%(asctime)s: %(levelname)s/%(processName)s] %(message)s
  1267. See the Python :mod:`logging` module for more information about log
  1268. formats.
  1269. .. setting:: worker_task_log_format
  1270. ``worker_task_log_format``
  1271. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1272. The format to use for log messages logged in tasks.
  1273. Default is:
  1274. .. code-block:: text
  1275. [%(asctime)s: %(levelname)s/%(processName)s]
  1276. [%(task_name)s(%(task_id)s)] %(message)s
  1277. See the Python :mod:`logging` module for more information about log
  1278. formats.
  1279. .. setting:: worker_redirect_stdouts
  1280. ``worker_redirect_stdouts``
  1281. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1282. If enabled `stdout` and `stderr` will be redirected
  1283. to the current logger.
  1284. Enabled by default.
  1285. Used by :program:`celery worker` and :program:`celery beat`.
  1286. .. setting:: worker_redirect_stdouts_level
  1287. ``worker_redirect_stdouts_level``
  1288. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1289. The log level output to `stdout` and `stderr` is logged as.
  1290. Can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
  1291. :const:`ERROR` or :const:`CRITICAL`.
  1292. Default is :const:`WARNING`.
  1293. .. _conf-security:
  1294. Security
  1295. --------
  1296. .. setting:: security_key
  1297. ``security_key``
  1298. ~~~~~~~~~~~~~~~~
  1299. .. versionadded:: 2.5
  1300. The relative or absolute path to a file containing the private key
  1301. used to sign messages when :ref:`message-signing` is used.
  1302. .. setting:: security_certificate
  1303. ``security_certificate``
  1304. ~~~~~~~~~~~~~~~~~~~~~~~~
  1305. .. versionadded:: 2.5
  1306. The relative or absolute path to an X.509 certificate file
  1307. used to sign messages when :ref:`message-signing` is used.
  1308. .. setting:: security_cert_store
  1309. ``security_cert_store``
  1310. ~~~~~~~~~~~~~~~~~~~~~~~
  1311. .. versionadded:: 2.5
  1312. The directory containing X.509 certificates used for
  1313. :ref:`message-signing`. Can be a glob with wild-cards,
  1314. (for example :file:`/etc/certs/*.pem`).
  1315. .. _conf-custom-components:
  1316. Custom Component Classes (advanced)
  1317. -----------------------------------
  1318. .. setting:: worker_pool
  1319. ``worker_pool``
  1320. ~~~~~~~~~~~~~~~
  1321. Name of the pool class used by the worker.
  1322. .. admonition:: Eventlet/Gevent
  1323. Never use this option to select the eventlet or gevent pool.
  1324. You must use the :option:`-P <celery worker -P>` option to
  1325. :program:`celery worker` instead, to ensure the monkey patches
  1326. are not applied too late, causing things to break in strange ways.
  1327. Default is ``celery.concurrency.prefork:TaskPool``.
  1328. .. setting:: worker_pool_restarts
  1329. ``worker_pool_restarts``
  1330. ~~~~~~~~~~~~~~~~~~~~~~~~
  1331. If enabled the worker pool can be restarted using the
  1332. :control:`pool_restart` remote control command.
  1333. Disabled by default.
  1334. .. setting:: worker_consumer
  1335. ``worker_consumer``
  1336. ~~~~~~~~~~~~~~~~~~~
  1337. Name of the consumer class used by the worker.
  1338. Default is :class:`celery.worker.consumer.Consumer`
  1339. .. setting:: worker_timer
  1340. ``worker_timer``
  1341. ~~~~~~~~~~~~~~~~
  1342. Name of the ETA scheduler class used by the worker.
  1343. Default is :class:`kombu.async.hub.timer.Timer`, or set by the
  1344. pool implementation.
  1345. .. _conf-celerybeat:
  1346. Beat Settings (:program:`celery beat`)
  1347. --------------------------------------
  1348. .. setting:: beat_schedule
  1349. ``beat_schedule``
  1350. ~~~~~~~~~~~~~~~~~
  1351. The periodic task schedule used by :mod:`~celery.bin.beat`.
  1352. See :ref:`beat-entries`.
  1353. .. setting:: beat_scheduler
  1354. ``beat_scheduler``
  1355. ~~~~~~~~~~~~~~~~~~
  1356. The default scheduler class. Default is ``celery.beat:PersistentScheduler``.
  1357. Can also be set via the :option:`celery beat -S` argument.
  1358. .. setting:: beat_schedule_filename
  1359. ``beat_schedule_filename``
  1360. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1361. Name of the file used by `PersistentScheduler` to store the last run times
  1362. of periodic tasks. Can be a relative or absolute path, but be aware that the
  1363. suffix `.db` may be appended to the file name (depending on Python version).
  1364. Can also be set via the :option:`celery beat --schedule` argument.
  1365. .. setting:: beat_sync_every
  1366. ``beat_sync_every``
  1367. ~~~~~~~~~~~~~~~~~~~
  1368. The number of periodic tasks that can be called before another database sync
  1369. is issued.
  1370. Defaults to 0 (sync based on timing - default of 3 minutes as determined by
  1371. scheduler.sync_every). If set to 1, beat will call sync after every task
  1372. message sent.
  1373. .. setting:: beat_max_loop_interval
  1374. ``beat_max_loop_interval``
  1375. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1376. The maximum number of seconds :mod:`~celery.bin.beat` can sleep
  1377. between checking the schedule.
  1378. The default for this value is scheduler specific.
  1379. For the default celery beat scheduler the value is 300 (5 minutes),
  1380. but for e.g. the :pypi:`django-celery` database scheduler it is 5 seconds
  1381. because the schedule may be changed externally, and so it must take
  1382. changes to the schedule into account.
  1383. Also when running celery beat embedded (:option:`-B <celery worker -B>`)
  1384. on Jython as a thread the max interval is overridden and set to 1 so
  1385. that it's possible to shut down in a timely manner.