Skip to content

Commit

Permalink
Merge pull request #11296 from akolson/halt-kolibri-startup
Browse files Browse the repository at this point in the history
Adds connection error exception to handle redis connection failure
  • Loading branch information
rtibbles authored Sep 29, 2023
2 parents 16e94a3 + 6a73c13 commit cdd31ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions kolibri/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions kolibri/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ class KolibriUpgradeError(KolibriError):
"""

pass


class RedisConnectionError(Exception):
pass

0 comments on commit cdd31ba

Please sign in to comment.