configuration.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. ============================
  2. Configuration and defaults
  3. ============================
  4. This document describes the configuration options available.
  5. If you're using celery in a Django project these settings should be defined
  6. in your projects ``settings.py`` file.
  7. In a regular Python environment using the default loader you must create
  8. the ``celeryconfig.py`` module and make sure it is available on the
  9. Python path.
  10. Example configuration file
  11. ==========================
  12. This is an example configuration file to get you started,
  13. it should contain all you need to run a basic celery set-up.
  14. .. code-block:: python
  15. CELERY_BACKEND = "database"
  16. DATABASE_ENGINE = "sqlite3"
  17. DATABASE_NAME = "mydatabase.db"
  18. BROKER_HOST = "localhost"
  19. BROKER_PORT = 5672
  20. BROKER_VHOST = "/"
  21. BROKER_USER = "guest"
  22. BROKER_PASSWORD = "guest"
  23. ## If you're doing mostly I/O you can have more processes,
  24. ## but if mostly spending CPU, try to keep it close to the
  25. ## number of CPUs on your machine. If not set, the number of CPUs/cores
  26. ## available will be used.
  27. # CELERYD_CONCURRENCY = 8
  28. # CELERYD_LOG_FILE = "celeryd.log"
  29. # CELERYD_LOG_LEVEL = "INFO"
  30. # CELERYD_PID_FILE = "celeryd.pid"
  31. Concurrency settings
  32. ====================
  33. * CELERYD_CONCURRENCY
  34. The number of concurrent worker processes, executing tasks simultaneously.
  35. Defaults to the number of CPUs/cores available.
  36. Task result backend settings
  37. ============================
  38. * CELERY_BACKEND
  39. The backend used to store task results (tombstones).
  40. Can be one of the following:
  41. * database (default)
  42. Use a relational database supported by the Django ORM.
  43. * cache
  44. Use `memcached`_ to store the results.
  45. * mongodb
  46. Use `MongoDB`_ to store the results.
  47. * pyredis
  48. Use `Redis`_ to store the results.
  49. * tyrant
  50. Use `Tokyo Tyrant`_ to store the results.
  51. * amqp
  52. Send results back as AMQP messages
  53. (**WARNING** While very fast, you must make sure you only
  54. try to receive the result once).
  55. .. _`memcached`: http://memcached.org
  56. .. _`MongoDB`: http://mongodb.org
  57. .. _`Redis`: http://code.google.com/p/redis/
  58. .. _`Tokyo Tyrant`: http://1978th.net/tokyotyrant/
  59. Database backend settings
  60. =========================
  61. Please see the Django ORM database settings documentation:
  62. http://docs.djangoproject.com/en/dev/ref/settings/#database-engine
  63. If you use this backend make sure to initialize the database tables
  64. after configuration. When using celery with a Django project this
  65. means executing::
  66. $ python manage.py syncdb
  67. When using celery in a regular Python environment you have to execute::
  68. $ celeryinit
  69. Example configuration
  70. ---------------------
  71. .. code-block:: python
  72. CELERY_BACKEND = "database"
  73. DATABASE_ENGINE = "mysql"
  74. DATABASE_USER = "myusername"
  75. DATABASE_PASSWORD = "mypassword"
  76. DATABASE_NAME = "mydatabase"
  77. DATABASE_HOST = "localhost"
  78. AMQP backend settings
  79. =====================
  80. The AMQP backend does not have any settings yet.
  81. Example configuration
  82. ---------------------
  83. CELERY_BACKEND = "amqp"
  84. Cache backend settings
  85. ======================
  86. Please see the documentation for the Django cache framework settings:
  87. http://docs.djangoproject.com/en/dev/topics/cache/#memcached
  88. To use a custom cache backend for Celery, while using another for Django,
  89. you should use the ``CELERY_CACHE_BACKEND`` setting instead of the regular
  90. django ``CACHE_BACKEND`` setting.
  91. Example configuration
  92. ---------------------
  93. Using a single memcached server:
  94. .. code-block:: python
  95. CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
  96. Using multiple memcached servers:
  97. .. code-block:: python
  98. CELERY_BACKEND = "cache"
  99. CACHE_BACKEND = 'memcached://172.19.26.240:11211;172.19.26.242:11211/'
  100. Tokyo Tyrant backend settings
  101. =============================
  102. **NOTE** The Tokyo Tyrant backend requires the :mod:`pytyrant` library:
  103. http://pypi.python.org/pypi/pytyrant/
  104. This backend requires the following configuration directives to be set:
  105. * TT_HOST
  106. Hostname of the Tokyo Tyrant server.
  107. * TT_PORT
  108. The port the Tokyo Tyrant server is listening to.
  109. Example configuration
  110. ---------------------
  111. .. code-block:: python
  112. CELERY_BACKEND = "tyrant"
  113. TT_HOST = "localhost"
  114. TT_PORT = 1978
  115. Redis backend settings
  116. ======================
  117. **NOTE** The Redis backend requires the :mod:`redis` library:
  118. http://pypi.python.org/pypi/redis/0.5.5
  119. To install the redis package use ``pip`` or ``easy_install``::
  120. $ pip install redis
  121. This backend requires the following configuration directives to be set:
  122. * REDIS_HOST
  123. Hostname of the Redis database server. e.g. ``"localhost"``.
  124. * REDIS_PORT
  125. Port to the Redis database server. e.g. ``6379``.
  126. Also, the following optional configuration directives are available:
  127. * REDIS_DB
  128. Name of the database to use. Default is ``celery_results``.
  129. * REDIS_TIMEOUT
  130. Timeout in seconds before we give up establishing a connection
  131. to the Redis server.
  132. * REDIS_CONNECT_RETRY
  133. Retry connecting if an connection could not be established. Default is
  134. false.
  135. Example configuration
  136. ---------------------
  137. .. code-block:: python
  138. CELERY_BACKEND = "pyredis"
  139. REDIS_HOST = "localhost"
  140. REDIS_PORT = 6739
  141. REDIS_DATABASE = "celery_results"
  142. REDIS_CONNECT_RETRY=True
  143. MongoDB backend settings
  144. ========================
  145. **NOTE** The MongoDB backend requires the :mod:`pymongo` library:
  146. http://github.com/mongodb/mongo-python-driver/tree/master
  147. * CELERY_MONGODB_BACKEND_SETTINGS
  148. This is a dict supporting the following keys:
  149. * host
  150. Hostname of the MongoDB server. Defaults to "localhost".
  151. * port
  152. The port the MongoDB server is listening to. Defaults to 27017.
  153. * user
  154. Username to authenticate to the MongoDB server as (optional).
  155. * password
  156. Password to authenticate to the MongoDB server (optional).
  157. * database
  158. The database name to connect to. Defaults to "celery".
  159. * taskmeta_collection
  160. The collection name to store task metadata.
  161. Defaults to "celery_taskmeta".
  162. Example configuration
  163. ---------------------
  164. .. code-block:: python
  165. CELERY_BACKEND = "mongodb"
  166. CELERY_MONGODB_BACKEND_SETTINGS = {
  167. "host": "192.168.1.100",
  168. "port": 30000,
  169. "database": "mydb",
  170. "taskmeta_collection": "my_taskmeta_collection",
  171. }
  172. Messaging settings
  173. ==================
  174. Routing
  175. -------
  176. * CELERY_QUEUES
  177. The mapping of queues the worker consumes from. This is a dictionary
  178. of queue name/options. See :doc:`userguide/routing` for more information.
  179. The default is a queue/exchange/binding key of ``"celery"``, with
  180. exchange type ``direct``.
  181. You don't have to care about this unless you want custom routing facilities.
  182. * CELERY_DEFAULT_QUEUE
  183. The queue used by default, if no custom queue is specified.
  184. This queue must be listed in ``CELERY_QUEUES``.
  185. The default is: ``celery``.
  186. * CELERY_DEFAULT_EXCHANGE
  187. Name of the default exchange to use when no custom exchange
  188. is specified.
  189. The default is: ``celery``.
  190. * CELERY_DEFAULT_EXCHANGE_TYPE
  191. Default exchange type used when no custom exchange is specified.
  192. The default is: ``direct``.
  193. * CELERY_DEFAULT_ROUTING_KEY
  194. The default routing key used when sending tasks.
  195. The default is: ``celery``.
  196. Connection
  197. ----------
  198. * CELERY_BROKER_CONNECTION_TIMEOUT
  199. The timeout in seconds before we give up establishing a connection
  200. to the AMQP server. Default is 4 seconds.
  201. * CELERY_BROKER_CONNECTION_RETRY
  202. Automatically try to re-establish the connection to the AMQP broker if
  203. it's lost.
  204. The time between retries is increased for each retry, and is
  205. not exhausted before ``CELERY_BROKER_CONNECTION_MAX_RETRIES`` is exceeded.
  206. This behaviour is on by default.
  207. * CELERY_BROKER_CONNECTION_MAX_RETRIES
  208. Maximum number of retries before we give up re-establishing a connection
  209. to the AMQP broker.
  210. If this is set to ``0`` or ``None``, we will retry forever.
  211. Default is 100 retries.
  212. Task execution settings
  213. =======================
  214. * CELERY_ALWAYS_EAGER
  215. If this is ``True``, all tasks will be executed locally by blocking
  216. until it is finished. ``apply_async`` and ``Task.delay`` will return
  217. a :class:`celery.result.EagerResult` which emulates the behaviour of
  218. :class:`celery.result.AsyncResult`, except the result has already
  219. been evaluated.
  220. Tasks will never be sent to the queue, but executed locally
  221. instead.
  222. * CELERY_IGNORE_RESULT
  223. Wheter to store the task return values or not (tombstones).
  224. If you still want to store errors, just not successful return values,
  225. you can set ``CELERY_STORE_ERRORS_EVEN_IF_IGNORED``.
  226. * CELERY_TASK_RESULT_EXPIRES
  227. Time (in seconds, or a :class:`datetime.timedelta` object) for when after
  228. stored task tombstones are deleted.
  229. **NOTE**: For the moment this only works for the database and MongoDB
  230. backends., except the result has already
  231. been evaluated.
  232. * CELERY_TASK_SERIALIZER
  233. A string identifying the default serialization
  234. method to use. Can be ``pickle`` (default),
  235. ``json``, ``yaml``, or any custom serialization methods that have
  236. been registered with :mod:`carrot.serialization.registry`.
  237. Default is ``pickle``.
  238. Worker: celeryd
  239. ===============
  240. * CELERY_IMPORTS
  241. A sequence of modules to import when the celery daemon starts. This is
  242. useful to add tasks if you are not using django or cannot use task
  243. autodiscovery.
  244. * CELERY_SEND_EVENTS
  245. Send events so the worker can be monitored by tools like ``celerymon``.
  246. * CELERY_SEND_TASK_ERROR_EMAILS
  247. If set to ``True``, errors in tasks will be sent to admins by e-mail.
  248. If unset, it will send the e-mails if ``settings.DEBUG`` is False.
  249. * CELERY_STORE_ERRORS_EVEN_IF_IGNORED
  250. If set, the worker stores all task errors in the result store even if
  251. ``Task.ignore_result`` is on.
  252. Logging
  253. -------
  254. * CELERYD_LOG_FILE
  255. The default filename the worker daemon logs messages to, can be
  256. overridden using the `--logfile`` option to ``celeryd``.
  257. The default is to log using ``stderr`` if running in the foreground,
  258. when running in the background, detached as a daemon, the default
  259. logfile is ``celeryd.log``.
  260. Can also be set via the ``--logfile`` argument.
  261. * CELERYD_LOG_LEVEL
  262. Worker log level, can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  263. ``ERROR``, ``CRITICAL``.
  264. Can also be set via the ``--loglevel`` argument.
  265. See the :mod:`logging` module for more information.
  266. * CELERYD_LOG_FORMAT
  267. The format to use for log messages. Can be overridden using
  268. the ``--loglevel`` option to ``celeryd``.
  269. Default is ``[%(asctime)s: %(levelname)s/%(processName)s] %(message)s``
  270. See the Python :mod:`logging` module for more information about log
  271. formats.
  272. Process
  273. -------
  274. * CELERYD_PID_FILE
  275. Full path to the pid file. Default is ``celeryd.pid``.
  276. Can also be set via the ``--pidfile`` argument.
  277. Periodic Task Server: celerybeat
  278. ================================
  279. * CELERYBEAT_SCHEDULE_FILENAME
  280. Name of the file celerybeat stores the current schedule in.
  281. Can be a relative or absolute path, but be aware that the suffix ``.db``
  282. will be appended to the filename.
  283. Can also be set via the ``--schedule`` argument.
  284. * CELERYBEAT_MAX_LOOP_INTERVAL
  285. The maximum number of seconds celerybeat can sleep between checking
  286. the schedule. Default is 300 seconds (5 minutes).
  287. * CELERYBEAT_LOG_FILE
  288. The default filename to log messages to, can be
  289. overridden using the `--logfile`` option.
  290. The default is to log using ``stderr`` if running in the foreground,
  291. when running in the background, detached as a daemon, the default
  292. logfile is ``celerybeat.log``.
  293. Can also be set via the ``--logfile`` argument.
  294. * CELERYBEAT_LOG_LEVEL
  295. Logging level. Can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  296. ``ERROR``, or ``CRITICAL``.
  297. Can also be set via the ``--loglevel`` argument.
  298. See the :mod:`logging` module for more information.
  299. * CELERYBEAT_PID_FILE
  300. Full path to celerybeat's pid file. Default is ``celerybat.pid``.
  301. Can also be set via the ``--pidfile`` argument.
  302. Monitor Server: celerymon
  303. =========================
  304. * CELERYMON_LOG_FILE
  305. The default filename to log messages to, can be
  306. overridden using the `--logfile`` option.
  307. The default is to log using ``stderr`` if running in the foreground,
  308. when running in the background, detached as a daemon, the default
  309. logfile is ``celerymon.log``.
  310. * CELERYMON_LOG_LEVEL
  311. Logging level. Can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  312. ``ERROR``, or ``CRITICAL``.
  313. See the :mod:`logging` module for more information.
  314. * CELERYMON_PID_FILE
  315. Full path to celerymon's pid file. Default is ``celerymon.pid``.
  316. Can be overridden using the ``--pidfile`` option to ``celerymon``.