conf.py 4.5 KB

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