conf.py 7.2 KB

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