diff --git a/kolibri/core/apps.py b/kolibri/core/apps.py index 4eb359dc8c..cc3d5d129c 100644 --- a/kolibri/core/apps.py +++ b/kolibri/core/apps.py @@ -10,7 +10,9 @@ from django.db.utils import DatabaseError from django_filters.filters import UUIDFilter from django_filters.rest_framework.filterset import FilterSet +from six import raise_from +from kolibri.core.errors import RedisConnectionError from kolibri.core.sqlite.pragmas import CONNECTION_PRAGMAS from kolibri.core.sqlite.pragmas import START_PRAGMAS from kolibri.core.sqlite.utils import repair_sqlite_db @@ -108,12 +110,15 @@ def activate_pragmas_on_start(): cursor.execute(START_PRAGMAS) connection.close() - @staticmethod - def check_redis_settings(): + @staticmethod # noqa C901 + def check_redis_settings(): # noqa C901 """ Check that Redis settings are sensible, and use the lower level Redis client to make updates if we are configured to do so, and if we should, otherwise make some logging noise. """ + + from redis.exceptions import ConnectionError + if OPTIONS["Cache"]["CACHE_BACKEND"] != "redis": return config_maxmemory = OPTIONS["Cache"]["CACHE_REDIS_MAXMEMORY"] @@ -161,6 +166,14 @@ def check_redis_settings(): "Problematic Redis settings detected, please see Redis configuration " "documentation for details: https://redis.io/topics/config" ) + + except ConnectionError as e: + logger.warning("Unable to connect to Redis: {}".format(str(e))) + + raise_from( + RedisConnectionError("Unable to connect to Redis: {}".format(str(e))), e + ) + except Exception as e: logger.warning("Unable to check Redis settings") logger.warning(e) diff --git a/kolibri/core/errors.py b/kolibri/core/errors.py index 1b352ae8ae..e4c6435903 100644 --- a/kolibri/core/errors.py +++ b/kolibri/core/errors.py @@ -17,3 +17,7 @@ class KolibriUpgradeError(KolibriError): """ pass + + +class RedisConnectionError(Exception): + pass