configuration.rst 62 KB

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