configuration.rst 19 KB

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