Skip to content

Commit

Permalink
Add connection check to CpEfdClient initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff committed Dec 17, 2024
1 parent 8f0eb1a commit 514729c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions python/lsst/cp/pipe/utilsEfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def __init__(self, efdInstance="usdf_efd", dieOnSearch=False, log=None):
self._databaseName = "efd"
self._databaseUrl = urljoin(f"https://{authDict['host']}", authDict["path"])

self.checkConnection()

def _getAuth(self, instanceAlias):
"""Get authorization credentials.
Expand Down Expand Up @@ -89,6 +91,23 @@ def _getAuth(self, instanceAlias):
else:
raise RuntimeError(f"Could not connect to {url}")

def checkConnection(self):
"""Check the connection to the EFD.
Raises
------
RuntimError :
Raised if the connection check fails.
"""
# The ping command will return 204 (No Content) on success.

params = {"wait_for_leader": "5s"}

response = requests.get(f"{self._databaseUrl}/ping", params=params, auth=self._auth)
response.raise_for_status()
if response.status_code != 204:
raise RuntimeError(f"Connection check failed for {self._databaseUrl}")

def getSchemaDtype(self, topicName):
"""Get datatypes for a topic.
Expand Down

0 comments on commit 514729c

Please sign in to comment.