apps.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from __future__ import unicode_literals
  2. from django.apps import AppConfig
  3. from django.core.exceptions import ImproperlyConfigured
  4. from django.conf import settings
  5. class ExtrasConfig(AppConfig):
  6. name = "extras"
  7. def ready(self):
  8. import extras.signals
  9. # Check that we can connect to the configured Redis database if webhooks are enabled.
  10. if settings.WEBHOOKS_ENABLED:
  11. try:
  12. import redis
  13. except ImportError:
  14. raise ImproperlyConfigured(
  15. "WEBHOOKS_ENABLED is True but the redis Python package is not installed. (Try 'pip install "
  16. "redis'.)"
  17. )
  18. try:
  19. rs = redis.Redis(
  20. host=settings.REDIS_HOST,
  21. port=settings.REDIS_PORT,
  22. db=settings.REDIS_DATABASE,
  23. password=settings.REDIS_PASSWORD or None,
  24. )
  25. rs.ping()
  26. except redis.exceptions.ConnectionError:
  27. raise ImproperlyConfigured(
  28. "Unable to connect to the Redis database. Check that the Redis configuration has been defined in "
  29. "configuration.py."
  30. )