From 4853634c2f1d1548f81676aaebe6b5f209b83d5e Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 11 Jul 2017 13:48:25 +0300 Subject: [PATCH] Switch health to use a data interface --- health/models_interface.py | 12 ++++++++++++ health/models_pre_oci.py | 8 ++++++++ health/services.py | 5 ++--- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 health/models_interface.py create mode 100644 health/models_pre_oci.py diff --git a/health/models_interface.py b/health/models_interface.py new file mode 100644 index 000000000..1d82ce934 --- /dev/null +++ b/health/models_interface.py @@ -0,0 +1,12 @@ +from abc import ABCMeta, abstractmethod +from six import add_metaclass + +@add_metaclass(ABCMeta) +class HealthCheckDataInterface(object): + """ + Interface that represents all data store interactions required by health checks. + """ + @abstractmethod + def check_health(self, app_config): + """ Returns True if the connection to the database is healthy and False otherwise. """ + pass diff --git a/health/models_pre_oci.py b/health/models_pre_oci.py new file mode 100644 index 000000000..54178a19b --- /dev/null +++ b/health/models_pre_oci.py @@ -0,0 +1,8 @@ +from data.model import health +from health.models_interface import HealthCheckDataInterface + +class PreOCIModel(HealthCheckDataInterface): + def check_health(self, app_config): + return health.check_health(app_config) + +pre_oci_model = PreOCIModel() diff --git a/health/services.py b/health/services.py index 66a8b4033..1946db5c5 100644 --- a/health/services.py +++ b/health/services.py @@ -1,6 +1,6 @@ import logging -from data.model import health from app import build_logs, storage +from health.models_pre_oci import pre_oci_model as model logger = logging.getLogger(__name__) @@ -27,10 +27,9 @@ def _check_registry_gunicorn(app): logger.exception('Exception when checking registry health: %s', registry_url) return False - def _check_database(app): """ Returns the status of the database, as accessed from this instance. """ - return health.check_health(app.config) + return model.check_health(app.config) def _check_redis(app): """ Returns the status of Redis, as accessed from this instance. """