Skip to content

Commit

Permalink
#241: Implement /ping on ICAT backend
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Aug 13, 2021
1 parent 7384a88 commit 05fdc70
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions datagateway_api/common/icat/backend.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging

from icat.exception import ICATSessionError
from icat.exception import ICATError, ICATSessionError

from datagateway_api.common.backend import Backend
from datagateway_api.common.exceptions import AuthenticationError
from datagateway_api.common.constants import Constants
from datagateway_api.common.exceptions import AuthenticationError, PythonICATError
from datagateway_api.common.helpers import queries_records
from datagateway_api.common.icat.helpers import (
create_entities,
Expand Down Expand Up @@ -34,6 +35,20 @@ class PythonICATBackend(Backend):
Class that contains functions to access and modify data in an ICAT database directly
"""

def ping(self, **kwargs):
log.info("Pinging ICAT to ensure API is alive and well")

client_pool = kwargs.get("client_pool")
client = get_cached_client(None, client_pool)

try:
entity_names = client.getEntityNames()
log.debug("Entity names on ping: %s", entity_names)
except ICATError as e:
raise PythonICATError(e)

return Constants.PING_OK_RESPONSE

def login(self, credentials, **kwargs):
log.info("Logging in to get session ID")
client_pool = kwargs.get("client_pool")
Expand Down

0 comments on commit 05fdc70

Please sign in to comment.