conf.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. """celery.conf"""
  2. from django.conf import settings
  3. import logging
  4. DEFAULT_AMQP_EXCHANGE = "celery"
  5. DEFAULT_AMQP_ROUTING_KEY = "celery"
  6. DEFAULT_AMQP_CONSUMER_QUEUE = "celery"
  7. DEFAULT_AMQP_EXCHANGE_TYPE = "direct"
  8. DEFAULT_DAEMON_CONCURRENCY = 10
  9. DEFAULT_QUEUE_WAKEUP_AFTER = 0.3
  10. DEFAULT_EMPTY_MSG_EMIT_EVERY = 5
  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_REAP_TIMEOUT = 30
  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://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol#Exchange_types_and_the_effect_of_bindings
  91. """
  92. AMQP_EXCHANGE_TYPE = getattr(settings, "CELERY_AMQP_EXCHANGE_TYPE",
  93. DEFAULT_AMQP_EXCHANGE_TYPE)
  94. """
  95. .. data:: AMQP_ROUTING_KEY
  96. The AMQP routing key.
  97. """
  98. AMQP_ROUTING_KEY = getattr(settings, "CELERY_AMQP_ROUTING_KEY",
  99. DEFAULT_AMQP_ROUTING_KEY)
  100. """
  101. .. data:: AMQP_CONSUMER_QUEUE
  102. The name of the AMQP queue.
  103. """
  104. AMQP_CONSUMER_QUEUE = getattr(settings, "CELERY_AMQP_CONSUMER_QUEUE",
  105. DEFAULT_AMQP_CONSUMER_QUEUE)
  106. REAP_TIMEOUT = DEFAULT_REAP_TIMEOUT