From 29d9175457896547927a99b66ee00e80167d8135 Mon Sep 17 00:00:00 2001 From: Amy Wieliczka Date: Tue, 19 Sep 2023 16:23:07 -0700 Subject: [PATCH] add a custom solr healthcheck --- calisphere/apps.py | 4 ++++ calisphere/solr_healthcheck.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 calisphere/solr_healthcheck.py diff --git a/calisphere/apps.py b/calisphere/apps.py index 2c5e9b0c9..b3a32e9c8 100644 --- a/calisphere/apps.py +++ b/calisphere/apps.py @@ -1,5 +1,6 @@ from django.apps import AppConfig from calisphere.registry_data import RegistryManager +from health_check.plugins import plugin_dir class CalisphereAppConfig(AppConfig): @@ -9,3 +10,6 @@ class CalisphereAppConfig(AppConfig): def ready(self): self.registry = RegistryManager() + + from .solr_healthcheck import SolrHealthCheckBackend + plugin_dir.register(SolrHealthCheckBackend) diff --git a/calisphere/solr_healthcheck.py b/calisphere/solr_healthcheck.py new file mode 100644 index 000000000..9cfba73ac --- /dev/null +++ b/calisphere/solr_healthcheck.py @@ -0,0 +1,16 @@ +from health_check.backends import BaseHealthCheckBackend +from cache_retry import SOLR + +class SolrHealthCheckBackend(BaseHealthCheckBackend): + #: The status endpoints will respond with a 200 status code + #: even if the check errors. + critical_service = False + + def check_status(self): + try: + resp = SOLR(q="cats") + except: + raise HealthCheckException + + def identifier(self): + return self.__class__.__name__ # Display name on the endpoint.