Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds connection error exception to handle redis connection failure #11296

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions kolibri/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django_filters.filters import UUIDFilter
from django_filters.rest_framework.filterset import FilterSet

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 +109,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 +165,12 @@ 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 RedisConnectionError("Unable to connect to Redis: {}".format(str(e)))
akolson marked this conversation as resolved.
Show resolved Hide resolved

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