conf.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. """celery.conf"""
  2. from django.conf import settings
  3. import logging
  4. DEFAULT_AMQP_EXCHANGE = "celery"
  5. DEFAULT_AMQP_PUBLISHER_ROUTING_KEY = "celery"
  6. DEFAULT_AMQP_CONSUMER_ROUTING_KEY = "celery"
  7. DEFAULT_AMQP_CONSUMER_QUEUE = "celery"
  8. DEFAULT_AMQP_EXCHANGE_TYPE = "direct"
  9. DEFAULT_DAEMON_CONCURRENCY = 0 # defaults to cpu count
  10. DEFAULT_DAEMON_PID_FILE = "celeryd.pid"
  11. DEFAULT_LOG_FMT = '[%(asctime)s: %(levelname)s/%(processName)s] %(message)s'
  12. DEFAULT_DAEMON_LOG_LEVEL = "INFO"
  13. DEFAULT_DAEMON_LOG_FILE = "celeryd.log"
  14. DEFAULT_AMQP_CONNECTION_TIMEOUT = 4
  15. DEFAULT_STATISTICS = False
  16. DEFAULT_STATISTICS_COLLECT_INTERVAL = 60 * 5
  17. DEFAULT_ALWAYS_EAGER = False
  18. """
  19. .. data:: LOG_LEVELS
  20. Mapping of log level names to :mod:`logging` module constants.
  21. """
  22. LOG_LEVELS = {
  23. "DEBUG": logging.DEBUG,
  24. "INFO": logging.INFO,
  25. "WARNING": logging.WARNING,
  26. "WARN": logging.WARNING,
  27. "ERROR": logging.ERROR,
  28. "CRITICAL": logging.CRITICAL,
  29. "FATAL": logging.FATAL,
  30. }
  31. """
  32. .. data:: LOG_FORMAT
  33. The format to use for log messages.
  34. Default is ``[%(asctime)s: %(levelname)s/%(processName)s] %(message)s``
  35. """
  36. LOG_FORMAT = getattr(settings, "CELERYD_DAEMON_LOG_FORMAT",
  37. DEFAULT_LOG_FMT)
  38. """
  39. .. data:: DAEMON_LOG_FILE
  40. The path to the deamon log file (if not set, ``stderr`` is used).
  41. """
  42. DAEMON_LOG_FILE = getattr(settings, "CELERYD_LOG_FILE",
  43. DEFAULT_DAEMON_LOG_FILE)
  44. """
  45. .. data:: DAEMON_LOG_LEVEL
  46. Celery daemon log level, can be any of ``DEBUG``, ``INFO``, ``WARNING``,
  47. ``ERROR``, ``CRITICAL``, or ``FATAL``. See the :mod:`logging` module
  48. for more information.
  49. """
  50. DAEMON_LOG_LEVEL = LOG_LEVELS[getattr(settings, "CELERYD_DAEMON_LOG_LEVEL",
  51. DEFAULT_DAEMON_LOG_LEVEL).upper()]
  52. """
  53. .. data:: DAEMON_PID_FILE
  54. Full path to the daemon pidfile.
  55. """
  56. DAEMON_PID_FILE = getattr(settings, "CELERYD_PID_FILE",
  57. DEFAULT_DAEMON_PID_FILE)
  58. """
  59. .. data:: DAEMON_CONCURRENCY
  60. The number of concurrent worker processes, executing tasks simultaneously.
  61. """
  62. DAEMON_CONCURRENCY = getattr(settings, "CELERYD_CONCURRENCY",
  63. DEFAULT_DAEMON_CONCURRENCY)
  64. """
  65. .. data:: AMQP_EXCHANGE
  66. Name of the AMQP exchange.
  67. """
  68. AMQP_EXCHANGE = getattr(settings, "CELERY_AMQP_EXCHANGE",
  69. DEFAULT_AMQP_EXCHANGE)
  70. """
  71. .. data:: AMQP_EXCHANGE_TYPE
  72. The type of exchange. If the exchange type is ``direct``, all messages
  73. receives all tasks. However, if the exchange type is ``topic``, you can
  74. route e.g. some tasks to one server, and others to the rest.
  75. See `Exchange types and the effect of bindings`_.
  76. .. _`Exchange types and the effect of bindings`: http://bit.ly/wpamqpexchanges
  77. """
  78. AMQP_EXCHANGE_TYPE = getattr(settings, "CELERY_AMQP_EXCHANGE_TYPE",
  79. DEFAULT_AMQP_EXCHANGE_TYPE)
  80. """
  81. .. data:: AMQP_PUBLISHER_ROUTING_KEY
  82. The default AMQP routing key used when publishing tasks.
  83. """
  84. AMQP_PUBLISHER_ROUTING_KEY = getattr(settings,
  85. "CELERY_AMQP_PUBLISHER_ROUTING_KEY",
  86. DEFAULT_AMQP_PUBLISHER_ROUTING_KEY)
  87. """
  88. .. data:: AMQP_CONSUMER_ROUTING_KEY
  89. The AMQP routing key used when consuming tasks.
  90. """
  91. AMQP_CONSUMER_ROUTING_KEY = getattr(settings,
  92. "CELERY_AMQP_CONSUMER_ROUTING_KEY",
  93. DEFAULT_AMQP_CONSUMER_ROUTING_KEY)
  94. """
  95. .. data:: AMQP_CONSUMER_QUEUE
  96. The name of the AMQP queue.
  97. """
  98. AMQP_CONSUMER_QUEUE = getattr(settings, "CELERY_AMQP_CONSUMER_QUEUE",
  99. DEFAULT_AMQP_CONSUMER_QUEUE)
  100. """
  101. .. data:: AMQP_CONNECTION_TIMEOUT
  102. The timeout in seconds before we give up establishing a connection
  103. to the AMQP server.
  104. """
  105. AMQP_CONNECTION_TIMEOUT = getattr(settings, "CELERY_AMQP_CONNECTION_TIMEOUT",
  106. DEFAULT_AMQP_CONNECTION_TIMEOUT)
  107. """
  108. .. data:: SEND_CELERY_TASK_ERROR_EMAILS
  109. If set to ``True``, errors in tasks will be sent to admins by e-mail.
  110. If unset, it will send the e-mails if ``settings.DEBUG`` is False.
  111. """
  112. SEND_CELERY_TASK_ERROR_EMAILS = getattr(settings,
  113. "SEND_CELERY_TASK_ERROR_EMAILS",
  114. not settings.DEBUG)
  115. """
  116. .. data:: STATISTICS_COLLECT_INTERVAL
  117. The interval in seconds of which the
  118. :class:`celery.task.CollectStatisticsTask`` is run.
  119. """
  120. STATISTICS_COLLECT_INTERVAL = getattr(settings,
  121. "CELERY_STATISTICS_COLLECT_INTERVAL",
  122. DEFAULT_STATISTICS_COLLECT_INTERVAL)
  123. """
  124. .. data:: ALWAYS_EAGER
  125. If this is ``True``, all tasks will be executed locally by blocking
  126. until it is finished. ``apply_async`` and ``delay_task`` will return
  127. a :class:`celery.result.EagerResult` which emulates the behaviour of
  128. an :class:`celery.result.AsyncResult`.
  129. """
  130. ALWAYS_EAGER = getattr(settings, "CELERY_ALWAYS_EAGER",
  131. DEFAULT_ALWAYS_EAGER)