conf.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. """celery.conf"""
  2. from celery.loaders import settings
  3. from datetime import timedelta
  4. import logging
  5. DEFAULT_AMQP_EXCHANGE = "celery"
  6. DEFAULT_AMQP_PUBLISHER_ROUTING_KEY = "celery"
  7. DEFAULT_AMQP_CONSUMER_ROUTING_KEY = "celery"
  8. DEFAULT_AMQP_CONSUMER_QUEUE = "celery"
  9. DEFAULT_AMQP_EXCHANGE_TYPE = "direct"
  10. DEFAULT_DAEMON_CONCURRENCY = 0 # defaults to cpu count
  11. DEFAULT_DAEMON_PID_FILE = "celeryd.pid"
  12. DEFAULT_LOG_FMT = '[%(asctime)s: %(levelname)s/%(processName)s] %(message)s'
  13. DEFAULT_DAEMON_LOG_LEVEL = "INFO"
  14. DEFAULT_DAEMON_LOG_FILE = "celeryd.log"
  15. DEFAULT_AMQP_CONNECTION_TIMEOUT = 4
  16. DEFAULT_STATISTICS = False
  17. DEFAULT_STATISTICS_COLLECT_INTERVAL = 60 * 5
  18. DEFAULT_ALWAYS_EAGER = False
  19. DEFAULT_TASK_RESULT_EXPIRES = timedelta(days=5)
  20. DEFAULT_AMQP_CONNECTION_RETRY = True
  21. DEFAULT_AMQP_CONNECTION_MAX_RETRIES = 100
  22. """
  23. .. data:: LOG_LEVELS
  24. Mapping of log level names to :mod:`logging` module constants.
  25. """
  26. LOG_LEVELS = {
  27. "DEBUG": logging.DEBUG,
  28. "INFO": logging.INFO,
  29. "WARNING": logging.WARNING,
  30. "WARN": logging.WARNING,
  31. "ERROR": logging.ERROR,
  32. "CRITICAL": logging.CRITICAL,
  33. "FATAL": logging.FATAL,
  34. }
  35. """
  36. .. data:: LOG_FORMAT
  37. The format to use for log messages.
  38. Default is ``[%(asctime)s: %(levelname)s/%(processName)s] %(message)s``
  39. """
  40. LOG_FORMAT = getattr(settings, "CELERYD_DAEMON_LOG_FORMAT",
  41. DEFAULT_LOG_FMT)
  42. """
  43. .. data:: DAEMON_LOG_FILE
  44. The path to the deamon log file (if not set, ``stderr`` is used).
  45. """
  46. DAEMON_LOG_FILE = getattr(settings, "CELERYD_LOG_FILE",
  47. DEFAULT_DAEMON_LOG_FILE)
  48. """
  49. .. data:: DAEMON_LOG_LEVEL
  50. Celery daemon log level, can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  51. ``ERROR``, ``CRITICAL``, or ``FATAL``. See the :mod:`logging` module
  52. for more information.
  53. """
  54. DAEMON_LOG_LEVEL = LOG_LEVELS[getattr(settings, "CELERYD_DAEMON_LOG_LEVEL",
  55. DEFAULT_DAEMON_LOG_LEVEL).upper()]
  56. """
  57. .. data:: DAEMON_PID_FILE
  58. Full path to the daemon pidfile.
  59. """
  60. DAEMON_PID_FILE = getattr(settings, "CELERYD_PID_FILE",
  61. DEFAULT_DAEMON_PID_FILE)
  62. """
  63. .. data:: DAEMON_CONCURRENCY
  64. The number of concurrent worker processes, executing tasks simultaneously.
  65. """
  66. DAEMON_CONCURRENCY = getattr(settings, "CELERYD_CONCURRENCY",
  67. DEFAULT_DAEMON_CONCURRENCY)
  68. """
  69. .. data:: AMQP_EXCHANGE
  70. Name of the AMQP exchange.
  71. """
  72. AMQP_EXCHANGE = getattr(settings, "CELERY_AMQP_EXCHANGE",
  73. DEFAULT_AMQP_EXCHANGE)
  74. """
  75. .. data:: AMQP_EXCHANGE_TYPE
  76. The type of exchange. If the exchange type is ``direct``, all messages
  77. receives all tasks. However, if the exchange type is ``topic``, you can
  78. route e.g. some tasks to one server, and others to the rest.
  79. See `Exchange types and the effect of bindings`_.
  80. .. _`Exchange types and the effect of bindings`: http://bit.ly/wpamqpexchanges
  81. """
  82. AMQP_EXCHANGE_TYPE = getattr(settings, "CELERY_AMQP_EXCHANGE_TYPE",
  83. DEFAULT_AMQP_EXCHANGE_TYPE)
  84. """
  85. .. data:: AMQP_PUBLISHER_ROUTING_KEY
  86. The default AMQP routing key used when publishing tasks.
  87. """
  88. AMQP_PUBLISHER_ROUTING_KEY = getattr(settings,
  89. "CELERY_AMQP_PUBLISHER_ROUTING_KEY",
  90. DEFAULT_AMQP_PUBLISHER_ROUTING_KEY)
  91. """
  92. .. data:: AMQP_CONSUMER_ROUTING_KEY
  93. The AMQP routing key used when consuming tasks.
  94. """
  95. AMQP_CONSUMER_ROUTING_KEY = getattr(settings,
  96. "CELERY_AMQP_CONSUMER_ROUTING_KEY",
  97. DEFAULT_AMQP_CONSUMER_ROUTING_KEY)
  98. """
  99. .. data:: AMQP_CONSUMER_QUEUE
  100. The name of the AMQP queue.
  101. """
  102. AMQP_CONSUMER_QUEUE = getattr(settings, "CELERY_AMQP_CONSUMER_QUEUE",
  103. DEFAULT_AMQP_CONSUMER_QUEUE)
  104. """
  105. .. data:: AMQP_CONSUMER_QUEUES
  106. Dictionary defining multiple AMQP queues.
  107. """
  108. DEFAULT_AMQP_CONSUMER_QUEUES = {
  109. AMQP_CONSUMER_QUEUE: {
  110. "exchange": AMQP_EXCHANGE,
  111. "routing_key": AMQP_CONSUMER_ROUTING_KEY,
  112. "exchange_type": AMQP_EXCHANGE_TYPE,
  113. }
  114. }
  115. AMQP_CONSUMER_QUEUES = getattr(settings, "CELERY_AMQP_CONSUMER_QUEUES",
  116. DEFAULT_AMQP_CONSUMER_QUEUES)
  117. """
  118. .. data:: AMQP_CONNECTION_TIMEOUT
  119. The timeout in seconds before we give up establishing a connection
  120. to the AMQP server.
  121. """
  122. AMQP_CONNECTION_TIMEOUT = getattr(settings, "CELERY_AMQP_CONNECTION_TIMEOUT",
  123. DEFAULT_AMQP_CONNECTION_TIMEOUT)
  124. """
  125. .. data:: SEND_CELERY_TASK_ERROR_EMAILS
  126. If set to ``True``, errors in tasks will be sent to admins by e-mail.
  127. If unset, it will send the e-mails if ``settings.DEBUG`` is False.
  128. """
  129. SEND_CELERY_TASK_ERROR_EMAILS = getattr(settings,
  130. "SEND_CELERY_TASK_ERROR_EMAILS",
  131. not settings.DEBUG)
  132. """
  133. .. data:: STATISTICS_COLLECT_INTERVAL
  134. The interval in seconds of which the
  135. :class:`celery.task.CollectStatisticsTask`` is run.
  136. """
  137. STATISTICS_COLLECT_INTERVAL = getattr(settings,
  138. "CELERY_STATISTICS_COLLECT_INTERVAL",
  139. DEFAULT_STATISTICS_COLLECT_INTERVAL)
  140. """
  141. .. data:: ALWAYS_EAGER
  142. If this is ``True``, all tasks will be executed locally by blocking
  143. until it is finished. ``apply_async`` and ``delay_task`` will return
  144. a :class:`celery.result.EagerResult` which emulates the behaviour of
  145. an :class:`celery.result.AsyncResult`.
  146. """
  147. ALWAYS_EAGER = getattr(settings, "CELERY_ALWAYS_EAGER",
  148. DEFAULT_ALWAYS_EAGER)
  149. """
  150. .. data: TASK_RESULT_EXPIRES
  151. Time (in seconds, or a :class:`datetime.timedelta` object) for when after
  152. stored task results are deleted. For the moment this only works for the
  153. database backend.
  154. """
  155. TASK_RESULT_EXPIRES = getattr(settings, "CELERY_TASK_RESULT_EXPIRES",
  156. DEFAULT_TASK_RESULT_EXPIRES)
  157. # Make sure TASK_RESULT_EXPIRES is a timedelta.
  158. if isinstance(TASK_RESULT_EXPIRES, int):
  159. TASK_RESULT_EXPIRES = timedelta(seconds=TASK_RESULT_EXPIRES)
  160. """
  161. .. data:: AMQP_CONNECTION_RETRY
  162. Automatically try to re-establish the connection to the AMQP broker if
  163. it's lost. The time between retries is increased for each retry, and is
  164. not exhausted before :data:`AMQP_CONNECTION_MAX_RETRIES` is exceeded.
  165. On by default.
  166. """
  167. AMQP_CONNECTION_RETRY = getattr(settings, "AMQP_CONNECTION_RETRY",
  168. DEFAULT_AMQP_CONNECTION_RETRY)
  169. """
  170. .. data:: AMQP_CONNECTION_MAX_RETRIES
  171. Maximum number of retries before we give up re-establishing a connection
  172. to the AMQP broker.
  173. If this is set to ``0`` or ``None``, we will retry forever.
  174. Default is ``100`` retries.
  175. """
  176. AMQP_CONNECTION_MAX_RETRIES = getattr(settings,
  177. "AMQP_CONNECTION_MAX_RETRIES",
  178. DEFAULT_AMQP_CONNECTION_MAX_RETRIES)