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