configuration.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. ============================
  2. Configuration and defaults
  3. ============================
  4. This document describes the configuration options available.
  5. If you're using the default loader, you must create the ``celeryconfig.py``
  6. module and make sure it is available on the Python path.
  7. Example configuration file
  8. ==========================
  9. This is an example configuration file to get you started.
  10. It should contain all you need to run a basic celery set-up.
  11. .. code-block:: python
  12. CELERY_RESULT_BACKEND = "database"
  13. CELERY_RESULT_DBURI = "sqlite:///mydatabase.db"
  14. BROKER_HOST = "localhost"
  15. BROKER_PORT = 5672
  16. BROKER_VHOST = "/"
  17. BROKER_USER = "guest"
  18. BROKER_PASSWORD = "guest"
  19. ## If you're doing mostly I/O you can have more processes,
  20. ## but if mostly spending CPU, try to keep it close to the
  21. ## number of CPUs on your machine. If not set, the number of CPUs/cores
  22. ## available will be used.
  23. # CELERYD_CONCURRENCY = 8
  24. # CELERYD_LOG_FILE = "celeryd.log"
  25. # CELERYD_LOG_LEVEL = "INFO"
  26. Concurrency settings
  27. ====================
  28. * CELERYD_CONCURRENCY
  29. The number of concurrent worker processes, executing tasks simultaneously.
  30. Defaults to the number of CPUs/cores available.
  31. * CELERYD_PREFETCH_MULTIPLIER
  32. How many messages to prefetch at a time multiplied by the number of
  33. concurrent processes. The default is 4 (four messages for each
  34. process). The default setting seems pretty good here. However, if you have
  35. very long running tasks waiting in the queue and you have to start the
  36. workers, note that the first worker to start will receive four times the
  37. number of messages initially. Thus the tasks may not be fairly balanced among the
  38. workers.
  39. Task result backend settings
  40. ============================
  41. * CELERY_RESULT_BACKEND
  42. The backend used to store task results (tombstones).
  43. Can be one of the following:
  44. * database (default)
  45. Use a relational database supported by `SQLAlchemy`_.
  46. * cache
  47. Use `memcached`_ to store the results.
  48. * mongodb
  49. Use `MongoDB`_ to store the results.
  50. * redis
  51. Use `Redis`_ to store the results.
  52. * tyrant
  53. Use `Tokyo Tyrant`_ to store the results.
  54. * amqp
  55. Send results back as AMQP messages
  56. (**WARNING** While very fast, you must make sure you only
  57. receive the result once. See :doc:`userguide/executing`).
  58. .. _`SQLAlchemy`: http://sqlalchemy.org
  59. .. _`memcached`: http://memcached.org
  60. .. _`MongoDB`: http://mongodb.org
  61. .. _`Redis`: http://code.google.com/p/redis/
  62. .. _`Tokyo Tyrant`: http://1978th.net/tokyotyrant/
  63. Database backend settings
  64. =========================
  65. Please see `Supported Databases`_ for a table of supported databases.
  66. To use this backend you need to configure it with an
  67. `Connection String`_, some examples include:
  68. .. code-block:: python
  69. # sqlite (filename)
  70. CELERY_RESULT_DBURI = "sqlite:///celerydb.sqlite"
  71. # mysql
  72. CELERY_RESULT_DBURI = "mysql://scott:tiger@localhost/foo"
  73. # postgresql
  74. CELERY_RESULT_DBURI = "postgresql://scott:tiger@localhost/mydatabase"
  75. # oracle
  76. CELERY_RESULT_DBURI = "oracle://scott:tiger@127.0.0.1:1521/sidname"
  77. See `Connection String`_ for more information about connection
  78. strings.
  79. To specify additional SQLAlchemy database engine options you can use
  80. the ``CELERY_RESULT_ENGINE_OPTIONS`` setting::
  81. # echo enables verbose logging from SQLAlchemy.
  82. CELERY_RESULT_ENGINE_OPTIONS = {"echo": True}
  83. .. _`Supported Databases`:
  84. http://www.sqlalchemy.org/docs/dbengine.html#supported-databases
  85. .. _`Connection String`:
  86. http://www.sqlalchemy.org/docs/dbengine.html#create-engine-url-arguments
  87. Please see the Django ORM database settings documentation:
  88. http://docs.djangoproject.com/en/dev/ref/settings/#database-engine
  89. If you use this backend, make sure to initialize the database tables
  90. after configuration. Use the ``celeryinit`` command to do so::
  91. $ celeryinit
  92. Example configuration
  93. ---------------------
  94. .. code-block:: python
  95. CELERY_RESULT_BACKEND = "database"
  96. CELERY_RESULT_DBURI = "mysql://user:password@host/dbname"
  97. AMQP backend settings
  98. =====================
  99. * CELERY_RESULT_EXCHANGE
  100. Name of the exchange to publish results in. Default is ``"celeryresults"``.
  101. * CELERY_RESULT_EXCHANGE_TYPE
  102. The exchange type of the result exchange. Default is to use a ``direct``
  103. exchange.
  104. * CELERY_RESULT_SERIALIZER
  105. Result message serialization format. Default is ``"pickle"``.
  106. * CELERY_RESULTS_PERSISTENT
  107. If set to ``True``, result messages will be persistent. This means the
  108. messages will not be lost after a broker restart. The default is for the
  109. results to be transient.
  110. Example configuration
  111. ---------------------
  112. CELERY_RESULT_BACKEND = "amqp"
  113. Cache backend settings
  114. ======================
  115. Please see the documentation for the Django cache framework settings:
  116. http://docs.djangoproject.com/en/dev/topics/cache/#memcached
  117. To use a custom cache backend for Celery, while using another for Django,
  118. you should use the ``CELERY_CACHE_BACKEND`` setting instead of the regular
  119. django ``CACHE_BACKEND`` setting.
  120. Example configuration
  121. ---------------------
  122. Using a single memcached server:
  123. .. code-block:: python
  124. CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
  125. Using multiple memcached servers:
  126. .. code-block:: python
  127. CELERY_RESULT_BACKEND = "cache"
  128. CACHE_BACKEND = 'memcached://172.19.26.240:11211;172.19.26.242:11211/'
  129. Tokyo Tyrant backend settings
  130. =============================
  131. **NOTE** The Tokyo Tyrant backend requires the :mod:`pytyrant` library:
  132. http://pypi.python.org/pypi/pytyrant/
  133. This backend requires the following configuration directives to be set:
  134. * TT_HOST
  135. Hostname of the Tokyo Tyrant server.
  136. * TT_PORT
  137. The port the Tokyo Tyrant server is listening to.
  138. Example configuration
  139. ---------------------
  140. .. code-block:: python
  141. CELERY_RESULT_BACKEND = "tyrant"
  142. TT_HOST = "localhost"
  143. TT_PORT = 1978
  144. Redis backend settings
  145. ======================
  146. **NOTE** The Redis backend requires the :mod:`redis` library:
  147. http://pypi.python.org/pypi/redis/0.5.5
  148. To install the redis package use ``pip`` or ``easy_install``::
  149. $ pip install redis
  150. This backend requires the following configuration directives to be set:
  151. * REDIS_HOST
  152. Hostname of the Redis database server. e.g. ``"localhost"``.
  153. * REDIS_PORT
  154. Port to the Redis database server. e.g. ``6379``.
  155. Also, the following optional configuration directives are available:
  156. * REDIS_DB
  157. Name of the database to use. Default is ``celery_results``.
  158. * REDIS_PASSWORD
  159. Password used to connect to the database.
  160. Example configuration
  161. ---------------------
  162. .. code-block:: python
  163. CELERY_RESULT_BACKEND = "redis"
  164. REDIS_HOST = "localhost"
  165. REDIS_PORT = 6379
  166. REDIS_DATABASE = "celery_results"
  167. REDIS_CONNECT_RETRY=True
  168. MongoDB backend settings
  169. ========================
  170. **NOTE** The MongoDB backend requires the :mod:`pymongo` library:
  171. http://github.com/mongodb/mongo-python-driver/tree/master
  172. * CELERY_MONGODB_BACKEND_SETTINGS
  173. This is a dict supporting the following keys:
  174. * host
  175. Hostname of the MongoDB server. Defaults to "localhost".
  176. * port
  177. The port the MongoDB server is listening to. Defaults to 27017.
  178. * user
  179. User name to authenticate to the MongoDB server as (optional).
  180. * password
  181. Password to authenticate to the MongoDB server (optional).
  182. * database
  183. The database name to connect to. Defaults to "celery".
  184. * taskmeta_collection
  185. The collection name to store task meta data.
  186. Defaults to "celery_taskmeta".
  187. Example configuration
  188. ---------------------
  189. .. code-block:: python
  190. CELERY_RESULT_BACKEND = "mongodb"
  191. CELERY_MONGODB_BACKEND_SETTINGS = {
  192. "host": "192.168.1.100",
  193. "port": 30000,
  194. "database": "mydb",
  195. "taskmeta_collection": "my_taskmeta_collection",
  196. }
  197. Messaging settings
  198. ==================
  199. Routing
  200. -------
  201. * CELERY_QUEUES
  202. The mapping of queues the worker consumes from. This is a dictionary
  203. of queue name/options. See :doc:`userguide/routing` for more information.
  204. The default is a queue/exchange/binding key of ``"celery"``, with
  205. exchange type ``direct``.
  206. You don't have to care about this unless you want custom routing facilities.
  207. * CELERY_DEFAULT_QUEUE
  208. The queue used by default, if no custom queue is specified.
  209. This queue must be listed in ``CELERY_QUEUES``.
  210. The default is: ``celery``.
  211. * CELERY_DEFAULT_EXCHANGE
  212. Name of the default exchange to use when no custom exchange
  213. is specified.
  214. The default is: ``celery``.
  215. * CELERY_DEFAULT_EXCHANGE_TYPE
  216. Default exchange type used when no custom exchange is specified.
  217. The default is: ``direct``.
  218. * CELERY_DEFAULT_ROUTING_KEY
  219. The default routing key used when sending tasks.
  220. The default is: ``celery``.
  221. * CELERY_DEFAULT_DELIVERY_MODE
  222. Can be ``transient`` or ``persistent``. Default is to send
  223. persistent messages.
  224. Connection
  225. ----------
  226. * CELERY_BROKER_CONNECTION_TIMEOUT
  227. The timeout in seconds before we give up establishing a connection
  228. to the AMQP server. Default is 4 seconds.
  229. * CELERY_BROKER_CONNECTION_RETRY
  230. Automatically try to re-establish the connection to the AMQP broker if
  231. it's lost.
  232. The time between retries is increased for each retry, and is
  233. not exhausted before ``CELERY_BROKER_CONNECTION_MAX_RETRIES`` is exceeded.
  234. This behavior is on by default.
  235. * CELERY_BROKER_CONNECTION_MAX_RETRIES
  236. Maximum number of retries before we give up re-establishing a connection
  237. to the AMQP broker.
  238. If this is set to ``0`` or ``None``, we will retry forever.
  239. Default is 100 retries.
  240. Task execution settings
  241. =======================
  242. * CELERY_ALWAYS_EAGER
  243. If this is ``True``, all tasks will be executed locally by blocking
  244. until it is finished. ``apply_async`` and ``Task.delay`` will return
  245. a :class:`celery.result.EagerResult` which emulates the behavior of
  246. :class:`celery.result.AsyncResult`, except the result has already
  247. been evaluated.
  248. Tasks will never be sent to the queue, but executed locally
  249. instead.
  250. * CELERY_EAGER_PROPAGATES_EXCEPTIONS
  251. If this is ``True``, eagerly executed tasks (using ``.apply``, or with
  252. ``CELERY_ALWAYS_EAGER`` on), will raise exceptions.
  253. It's the same as always running ``apply`` with ``throw=True``.
  254. * CELERY_IGNORE_RESULT
  255. Whether to store the task return values or not (tombstones).
  256. If you still want to store errors, just not successful return values,
  257. you can set ``CELERY_STORE_ERRORS_EVEN_IF_IGNORED``.
  258. * CELERY_TASK_RESULT_EXPIRES
  259. Time (in seconds, or a :class:`datetime.timedelta` object) for when after
  260. stored task tombstones will be deleted.
  261. A built-in periodic task will delete the results after this time
  262. (:class:`celery.task.builtins.DeleteExpiredTaskMetaTask`).
  263. **NOTE**: For the moment this only works with the database, cache and MongoDB
  264. backends.
  265. **NOTE**: ``celerybeat`` must be running for the results to be expired.
  266. * CELERY_MAX_CACHED_RESULTS
  267. Total number of results to store before results are evicted from the
  268. result cache. The default is ``5000``.
  269. * CELERY_TRACK_STARTED
  270. If ``True`` the task will report its status as "started"
  271. when the task is executed by a worker.
  272. The default value is ``False`` as the normal behaviour is to not
  273. report that level of granularity. Tasks are either pending, finished,
  274. or waiting to be retried. Having a "started" status can be useful for
  275. when there are long running tasks and there is a need to report which
  276. task is currently running.
  277. backends.
  278. * CELERY_TASK_SERIALIZER
  279. A string identifying the default serialization
  280. method to use. Can be ``pickle`` (default),
  281. ``json``, ``yaml``, or any custom serialization methods that have
  282. been registered with :mod:`carrot.serialization.registry`.
  283. Default is ``pickle``.
  284. * CELERY_DEFAULT_RATE_LIMIT
  285. The global default rate limit for tasks.
  286. This value is used for tasks that does not have a custom rate limit
  287. The default is no rate limit.
  288. * CELERY_DISABLE_RATE_LIMITS
  289. Disable all rate limits, even if tasks has explicit rate limits set.
  290. * CELERY_ACKS_LATE
  291. Late ack means the task messages will be acknowledged **after** the task
  292. has been executed, not *just before*, which is the default behavior.
  293. See http://ask.github.com/celery/faq.html#should-i-use-retry-or-acks-late
  294. Worker: celeryd
  295. ===============
  296. * CELERY_IMPORTS
  297. A sequence of modules to import when the celery daemon starts. This is
  298. useful to add tasks if you are not using django or cannot use task
  299. auto-discovery.
  300. * CELERYD_MAX_TASKS_PER_CHILD
  301. Maximum number of tasks a pool worker process can execute before
  302. it's replaced with a new one. Default is no limit.
  303. * CELERYD_TASK_TIME_LIMIT
  304. Task hard time limit in seconds. The worker processing the task will
  305. be killed and replaced with a new one when this is exceeded.
  306. * CELERYD_SOFT_TASK_TIME_LIMIT
  307. Task soft time limit in seconds.
  308. The :exc:`celery.exceptions.SoftTimeLimitExceeded` exception will be
  309. raised when this is exceeded. The task can catch this to
  310. e.g. clean up before the hard time limit comes.
  311. .. code-block:: python
  312. from celery.decorators import task
  313. from celery.exceptions import SoftTimeLimitExceeded
  314. @task()
  315. def mytask():
  316. try:
  317. return do_work()
  318. except SoftTimeLimitExceeded:
  319. cleanup_in_a_hurry()
  320. * CELERY_SEND_TASK_ERROR_EMAILS
  321. If set to ``True``, errors in tasks will be sent to admins by e-mail.
  322. If unset, it will send the e-mails if ``settings.DEBUG`` is False.
  323. * CELERY_STORE_ERRORS_EVEN_IF_IGNORED
  324. If set, the worker stores all task errors in the result store even if
  325. ``Task.ignore_result`` is on.
  326. Events
  327. ------
  328. * CELERY_SEND_EVENTS
  329. Send events so the worker can be monitored by tools like ``celerymon``.
  330. * CELERY_EVENT_EXCHANGE
  331. Name of the exchange to send event messages to. Default is
  332. ``"celeryevent"``.
  333. * CELERY_EVENT_EXCHANGE_TYPE
  334. The exchange type of the event exchange. Default is to use a ``direct``
  335. exchange.
  336. * CELERY_EVENT_ROUTING_KEY
  337. Routing key used when sending event messages. Default is
  338. ``"celeryevent"``.
  339. * CELERY_EVENT_SERIALIZER
  340. Message serialization format used when sending event messages. Default is
  341. ``"json"``.
  342. Broadcast Commands
  343. ------------------
  344. * CELERY_BROADCAST_QUEUE
  345. Name prefix for the queue used when listening for
  346. broadcast messages. The workers hostname will be appended
  347. to the prefix to create the final queue name.
  348. Default is ``"celeryctl"``.
  349. * CELERY_BROADCAST_EXCHANGE
  350. Name of the exchange used for broadcast messages.
  351. Default is ``"celeryctl"``.
  352. * CELERY_BROADCAST_EXCHANGE_TYPE
  353. Exchange type used for broadcast messages. Default is ``"fanout"``.
  354. Logging
  355. -------
  356. * CELERYD_LOG_FILE
  357. The default file name the worker daemon logs messages to, can be
  358. overridden using the `--logfile`` option to ``celeryd``.
  359. The default is ``None`` (``stderr``)
  360. Can also be set via the ``--logfile`` argument.
  361. * CELERYD_LOG_LEVEL
  362. Worker log level, can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  363. ``ERROR``, ``CRITICAL``.
  364. Can also be set via the ``--loglevel`` argument.
  365. See the :mod:`logging` module for more information.
  366. * CELERYD_LOG_FORMAT
  367. The format to use for log messages.
  368. Default is ``[%(asctime)s: %(levelname)s/%(processName)s] %(message)s``
  369. See the Python :mod:`logging` module for more information about log
  370. formats.
  371. * CELERYD_TASK_LOG_FORMAT
  372. The format to use for log messages logged in tasks. Can be overridden using
  373. the ``--loglevel`` option to ``celeryd``.
  374. Default is::
  375. [%(asctime)s: %(levelname)s/%(processName)s]
  376. [%(task_name)s(%(task_id)s)] %(message)s
  377. See the Python :mod:`logging` module for more information about log
  378. formats.
  379. Custom Component Classes (advanced)
  380. -----------------------------------
  381. * CELERYD_POOL
  382. Name of the task pool class used by the worker.
  383. Default is ``"celery.concurrency.processes.TaskPool"``.
  384. * CELERYD_LISTENER
  385. Name of the listener class used by the worker.
  386. Default is ``"celery.worker.listener.CarrotListener"``.
  387. * CELERYD_MEDIATOR
  388. Name of the mediator class used by the worker.
  389. Default is ``"celery.worker.controllers.Mediator"``.
  390. * CELERYD_ETA_SCHEDULER
  391. Name of the ETA scheduler class used by the worker.
  392. Default is ``"celery.worker.controllers.ScheduleController"``.
  393. Periodic Task Server: celerybeat
  394. ================================
  395. * CELERYBEAT_SCHEDULE_FILENAME
  396. Name of the file celerybeat stores the current schedule in.
  397. Can be a relative or absolute path, but be aware that the suffix ``.db``
  398. will be appended to the file name.
  399. Can also be set via the ``--schedule`` argument.
  400. * CELERYBEAT_MAX_LOOP_INTERVAL
  401. The maximum number of seconds celerybeat can sleep between checking
  402. the schedule. Default is 300 seconds (5 minutes).
  403. * CELERYBEAT_LOG_FILE
  404. The default file name to log messages to, can be
  405. overridden using the `--logfile`` option.
  406. The default is ``None`` (``stderr``).
  407. Can also be set via the ``--logfile`` argument.
  408. * CELERYBEAT_LOG_LEVEL
  409. Logging level. Can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  410. ``ERROR``, or ``CRITICAL``.
  411. Can also be set via the ``--loglevel`` argument.
  412. See the :mod:`logging` module for more information.
  413. Monitor Server: celerymon
  414. =========================
  415. * CELERYMON_LOG_FILE
  416. The default file name to log messages to, can be
  417. overridden using the `--logfile`` option.
  418. The default is ``None`` (``stderr``)
  419. Can also be set via the ``--logfile`` argument.
  420. * CELERYMON_LOG_LEVEL
  421. Logging level. Can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  422. ``ERROR``, or ``CRITICAL``.
  423. See the :mod:`logging` module for more information.