conf.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.3
  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. DEFAULT_REAP_TIMEOUT = 30
  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:: QUEUE_WAKEUP_AFTER
  53. The time (in seconds) the celery worker should sleep when there's
  54. no messages left on the queue. After the time is slept, the worker
  55. wakes up and checks the queue again.
  56. """
  57. QUEUE_WAKEUP_AFTER = getattr(settings, "CELERYD_QUEUE_WAKEUP_AFTER",
  58. DEFAULT_QUEUE_WAKEUP_AFTER)
  59. """
  60. .. data:: EMPTY_MSG_EMIT_EVERY
  61. How often the celery daemon should write a log message saying there are no
  62. messages in the queue. If this is ``None`` or ``0``, it will never print
  63. this message.
  64. """
  65. EMPTY_MSG_EMIT_EVERY = getattr(settings, "CELERYD_EMPTY_MSG_EMIT_EVERY",
  66. DEFAULT_EMPTY_MSG_EMIT_EVERY)
  67. """
  68. .. data:: DAEMON_PID_FILE
  69. Full path to the daemon pidfile.
  70. """
  71. DAEMON_PID_FILE = getattr(settings, "CELERYD_PID_FILE",
  72. DEFAULT_DAEMON_PID_FILE)
  73. """
  74. .. data:: DAEMON_CONCURRENCY
  75. The number of concurrent worker processes, executing tasks simultaneously.
  76. """
  77. DAEMON_CONCURRENCY = getattr(settings, "CELERYD_CONCURRENCY",
  78. DEFAULT_DAEMON_CONCURRENCY)
  79. """
  80. .. data:: AMQP_EXCHANGE
  81. Name of the AMQP exchange.
  82. """
  83. AMQP_EXCHANGE = getattr(settings, "CELERY_AMQP_EXCHANGE",
  84. DEFAULT_AMQP_EXCHANGE)
  85. """
  86. .. data:: AMQP_EXCHANGE_TYPE
  87. The type of exchange. If the exchange type is ``direct``, all messages
  88. receives all tasks. However, if the exchange type is ``topic``, you can
  89. route e.g. some tasks to one server, and others to the rest.
  90. See `Exchange types and the effect of bindings`_.
  91. .. _`Exchange types and the effect of bindings:
  92. http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol
  93. #Exchange_types_and_the_effect_of_bindings
  94. """
  95. AMQP_EXCHANGE_TYPE = getattr(settings, "CELERY_AMQP_EXCHANGE_TYPE",
  96. DEFAULT_AMQP_EXCHANGE_TYPE)
  97. """
  98. .. data:: AMQP_PUBLISHER_ROUTING_KEY
  99. The default AMQP routing key used when publishing tasks.
  100. """
  101. AMQP_PUBLISHER_ROUTING_KEY = getattr(settings,
  102. "CELERY_AMQP_PUBLISHER_ROUTING_KEY",
  103. DEFAULT_AMQP_PUBLISHER_ROUTING_KEY)
  104. """
  105. .. data:: AMQP_CONSUMER_ROUTING_KEY
  106. The AMQP routing key used when consuming tasks.
  107. """
  108. AMQP_CONSUMER_ROUTING_KEY = getattr(settings,
  109. "CELERY_AMQP_CONSUMER_ROUTING_KEY",
  110. DEFAULT_AMQP_CONSUMER_ROUTING_KEY)
  111. """
  112. .. data:: AMQP_CONSUMER_QUEUE
  113. The name of the AMQP queue.
  114. """
  115. AMQP_CONSUMER_QUEUE = getattr(settings, "CELERY_AMQP_CONSUMER_QUEUE",
  116. DEFAULT_AMQP_CONSUMER_QUEUE)
  117. REAP_TIMEOUT = DEFAULT_REAP_TIMEOUT