From f9013a1552dd5a8fc5aaba4be3d88341dbb4f492 Mon Sep 17 00:00:00 2001 From: Cristiano Urban Date: Mon, 13 Sep 2021 14:34:03 +0200 Subject: [PATCH] Added 'getStorageHostname()' method + increased connection retries and wait time. Signed-off-by: Cristiano Urban --- transfer_service/db_connector.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/transfer_service/db_connector.py b/transfer_service/db_connector.py index 42ce885..010d748 100644 --- a/transfer_service/db_connector.py +++ b/transfer_service/db_connector.py @@ -44,7 +44,7 @@ class DbConnector(object): connect_timeout = 0 ) - def getConnection(self, retry = 5, timeout = 2): + def getConnection(self, retry = 10, timeout = 30): if retry < 1: retry = 1 if timeout < 1: @@ -702,6 +702,26 @@ class DbConnector(object): finally: self.connPool.putconn(conn, close = False) + def getStorageHostname(self, storageId): + """Returns the storage hostname for a given storage id, if any. Otherwise it returns 'False'.""" + conn = self.getConnection() + try: + cursor = conn.cursor(cursor_factory = RealDictCursor) + cursor.execute("SELECT hostname FROM storage WHERE storage_id = %s;", (storageId,)) + result = cursor.fetchall() + cursor.close() + except Exception: + if not conn.closed: + conn.rollback() + raise + else: + if result: + return result[0]["hostname"] + else: + return False + finally: + self.connPool.putconn(conn, close = False) + ##### Location ##### def getLocationId(self, destStorageId): -- GitLab