configuration.rst 61 KB

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