configuration.rst 19 KB

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