2018-05-30 11:19:10 -04:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.apps import AppConfig
|
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
|
|
|
|
class ExtrasConfig(AppConfig):
|
|
|
|
name = "extras"
|
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
import extras.signals
|
|
|
|
|
2018-05-30 14:51:59 -04:00
|
|
|
# Check that we can connect to the configured Redis database if webhooks are enabled.
|
|
|
|
if settings.WEBHOOKS_ENABLED:
|
2018-05-30 11:19:10 -04:00
|
|
|
try:
|
|
|
|
import redis
|
2018-05-30 14:51:59 -04:00
|
|
|
except ImportError:
|
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"WEBHOOKS_ENABLED is True but the redis Python package is not installed. (Try 'pip install "
|
|
|
|
"redis'.)"
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
rs = redis.Redis(
|
|
|
|
host=settings.REDIS_HOST,
|
|
|
|
port=settings.REDIS_PORT,
|
|
|
|
db=settings.REDIS_DATABASE,
|
|
|
|
password=settings.REDIS_PASSWORD or None,
|
|
|
|
)
|
2018-05-30 11:19:10 -04:00
|
|
|
rs.ping()
|
|
|
|
except redis.exceptions.ConnectionError:
|
|
|
|
raise ImproperlyConfigured(
|
2018-05-30 14:51:59 -04:00
|
|
|
"Unable to connect to the Redis database. Check that the Redis configuration has been defined in "
|
|
|
|
"configuration.py."
|
2018-05-30 11:19:10 -04:00
|
|
|
)
|