conf.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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_ALWAYS_EAGER = False
  18. DEFAULT_TASK_RESULT_EXPIRES = timedelta(days=5)
  19. DEFAULT_AMQP_CONNECTION_RETRY = True
  20. DEFAULT_AMQP_CONNECTION_MAX_RETRIES = 100
  21. DEFAULT_TASK_SERIALIZER = "pickle"
  22. DEFAULT_BACKEND = "database"
  23. DEFAULT_PERIODIC_STATUS_BACKEND = "database"
  24. """
  25. .. data:: LOG_LEVELS
  26. Mapping of log level names to :mod:`logging` module constants.
  27. """
  28. LOG_LEVELS = {
  29. "DEBUG": logging.DEBUG,
  30. "INFO": logging.INFO,
  31. "WARNING": logging.WARNING,
  32. "WARN": logging.WARNING,
  33. "ERROR": logging.ERROR,
  34. "CRITICAL": logging.CRITICAL,
  35. "FATAL": logging.FATAL,
  36. }
  37. """
  38. .. data:: LOG_FORMAT
  39. The format to use for log messages.
  40. """
  41. LOG_FORMAT = getattr(settings, "CELERYD_DAEMON_LOG_FORMAT",
  42. DEFAULT_LOG_FMT)
  43. """
  44. .. data:: DAEMON_LOG_FILE
  45. Filename of the daemon log file.
  46. """
  47. DAEMON_LOG_FILE = getattr(settings, "CELERYD_LOG_FILE",
  48. DEFAULT_DAEMON_LOG_FILE)
  49. """
  50. .. data:: DAEMON_LOG_LEVEL
  51. """
  52. DAEMON_LOG_LEVEL = LOG_LEVELS[getattr(settings, "CELERYD_DAEMON_LOG_LEVEL",
  53. DEFAULT_DAEMON_LOG_LEVEL).upper()]
  54. """
  55. .. data:: DAEMON_PID_FILE
  56. Full path to the daemon pidfile.
  57. """
  58. DAEMON_PID_FILE = getattr(settings, "CELERYD_PID_FILE",
  59. DEFAULT_DAEMON_PID_FILE)
  60. """
  61. .. data:: DAEMON_CONCURRENCY
  62. The number of concurrent worker processes.
  63. """
  64. DAEMON_CONCURRENCY = getattr(settings, "CELERYD_CONCURRENCY",
  65. DEFAULT_DAEMON_CONCURRENCY)
  66. """
  67. .. data:: AMQP_EXCHANGE
  68. Name of the AMQP exchange.
  69. """
  70. AMQP_EXCHANGE = getattr(settings, "CELERY_AMQP_EXCHANGE",
  71. DEFAULT_AMQP_EXCHANGE)
  72. """
  73. .. data:: AMQP_EXCHANGE_TYPE
  74. The exchange type.
  75. """
  76. AMQP_EXCHANGE_TYPE = getattr(settings, "CELERY_AMQP_EXCHANGE_TYPE",
  77. DEFAULT_AMQP_EXCHANGE_TYPE)
  78. """
  79. .. data:: AMQP_PUBLISHER_ROUTING_KEY
  80. The default AMQP routing key used when publishing tasks.
  81. """
  82. AMQP_PUBLISHER_ROUTING_KEY = getattr(settings,
  83. "CELERY_AMQP_PUBLISHER_ROUTING_KEY",
  84. DEFAULT_AMQP_PUBLISHER_ROUTING_KEY)
  85. """
  86. .. data:: AMQP_CONSUMER_ROUTING_KEY
  87. The AMQP routing key used when consuming tasks.
  88. """
  89. AMQP_CONSUMER_ROUTING_KEY = getattr(settings,
  90. "CELERY_AMQP_CONSUMER_ROUTING_KEY",
  91. DEFAULT_AMQP_CONSUMER_ROUTING_KEY)
  92. """
  93. .. data:: AMQP_CONSUMER_QUEUE
  94. The name of the AMQP queue.
  95. """
  96. AMQP_CONSUMER_QUEUE = getattr(settings, "CELERY_AMQP_CONSUMER_QUEUE",
  97. DEFAULT_AMQP_CONSUMER_QUEUE)
  98. """
  99. .. data:: AMQP_CONSUMER_QUEUES
  100. Dictionary defining multiple AMQP queues.
  101. """
  102. DEFAULT_AMQP_CONSUMER_QUEUES = {
  103. AMQP_CONSUMER_QUEUE: {
  104. "exchange": AMQP_EXCHANGE,
  105. "routing_key": AMQP_CONSUMER_ROUTING_KEY,
  106. "exchange_type": AMQP_EXCHANGE_TYPE,
  107. }
  108. }
  109. AMQP_CONSUMER_QUEUES = getattr(settings, "CELERY_AMQP_CONSUMER_QUEUES",
  110. DEFAULT_AMQP_CONSUMER_QUEUES)
  111. """
  112. .. data:: AMQP_CONNECTION_TIMEOUT
  113. The timeout in seconds before we give up establishing a connection
  114. to the AMQP server.
  115. """
  116. AMQP_CONNECTION_TIMEOUT = getattr(settings, "CELERY_AMQP_CONNECTION_TIMEOUT",
  117. DEFAULT_AMQP_CONNECTION_TIMEOUT)
  118. """
  119. .. data:: SEND_CELERY_TASK_ERROR_EMAILS
  120. If set to ``True``, errors in tasks will be sent to admins by e-mail.
  121. If unset, it will send the e-mails if ``settings.DEBUG`` is False.
  122. """
  123. SEND_CELERY_TASK_ERROR_EMAILS = getattr(settings,
  124. "SEND_CELERY_TASK_ERROR_EMAILS",
  125. not settings.DEBUG)
  126. """
  127. .. data:: ALWAYS_EAGER
  128. Always execute tasks locally, don't send to the queue.
  129. """
  130. ALWAYS_EAGER = getattr(settings, "CELERY_ALWAYS_EAGER",
  131. DEFAULT_ALWAYS_EAGER)
  132. """
  133. .. data: TASK_RESULT_EXPIRES
  134. Task tombstone expire time in seconds.
  135. """
  136. TASK_RESULT_EXPIRES = getattr(settings, "CELERY_TASK_RESULT_EXPIRES",
  137. DEFAULT_TASK_RESULT_EXPIRES)
  138. # Make sure TASK_RESULT_EXPIRES is a timedelta.
  139. if isinstance(TASK_RESULT_EXPIRES, int):
  140. TASK_RESULT_EXPIRES = timedelta(seconds=TASK_RESULT_EXPIRES)
  141. """
  142. .. data:: AMQP_CONNECTION_RETRY
  143. Automatically try to re-establish the connection to the AMQP broker if
  144. it's lost.
  145. """
  146. AMQP_CONNECTION_RETRY = getattr(settings, "CELERY_AMQP_CONNECTION_RETRY",
  147. DEFAULT_AMQP_CONNECTION_RETRY)
  148. """
  149. .. data:: AMQP_CONNECTION_MAX_RETRIES
  150. Maximum number of retries before we give up re-establishing a connection
  151. to the AMQP broker.
  152. If this is set to ``0`` or ``None``, we will retry forever.
  153. Default is ``100`` retries.
  154. """
  155. AMQP_CONNECTION_MAX_RETRIES = getattr(settings,
  156. "CELERY_AMQP_CONNECTION_MAX_RETRIES",
  157. DEFAULT_AMQP_CONNECTION_MAX_RETRIES)
  158. """
  159. .. data:: TASK_SERIALIZER
  160. A string identifying the default serialization
  161. method to use. Can be ``pickle`` (default),
  162. ``json``, ``yaml``, or any custom serialization methods that have
  163. been registered with :mod:`carrot.serialization.registry`.
  164. Default is ``pickle``.
  165. """
  166. TASK_SERIALIZER = getattr(settings, "CELERY_TASK_SERIALIZER",
  167. DEFAULT_TASK_SERIALIZER)
  168. """
  169. .. data:: CELERY_BACKEND
  170. The backend used to store task results (tombstones).
  171. """
  172. CELERY_BACKEND = getattr(settings, "CELERY_BACKEND", DEFAULT_BACKEND)
  173. """
  174. .. data:: CELERY_PERIODIC_STATUS_BACKEND
  175. The backend used to store the status of periodic tasks.
  176. """
  177. CELERY_PERIODIC_STATUS_BACKEND = getattr(settings,
  178. "CELERY_PERIODIC_STATUS_BACKEND",
  179. DEFAULT_PERIODIC_STATUS_BACKEND)