apps.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from django.apps import AppConfig
  2. from django.conf import settings
  3. from django.core.exceptions import ImproperlyConfigured
  4. class ExtrasConfig(AppConfig):
  5. name = "extras"
  6. def ready(self):
  7. import extras.signals
  8. # Check that we can connect to the configured Redis database if webhooks are enabled.
  9. if settings.WEBHOOKS_ENABLED:
  10. try:
  11. import redis
  12. except ImportError:
  13. raise ImproperlyConfigured(
  14. "WEBHOOKS_ENABLED is True but the redis Python package is not installed. (Try 'pip install "
  15. "redis'.)"
  16. )
  17. try:
  18. rs = redis.Redis(
  19. host=settings.REDIS_HOST,
  20. port=settings.REDIS_PORT,
  21. db=settings.REDIS_DATABASE,
  22. password=settings.REDIS_PASSWORD or None,
  23. ssl=settings.REDIS_SSL,
  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. )