From 4c06b2e3e9473ca474883d58761347642047e467 Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Fri, 15 Apr 2016 10:16:23 +0000 Subject: [PATCH] Task #8887: check validity of connection. reconnect if needed --- SAS/MoM/MoMQueryService/momqueryservice.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SAS/MoM/MoMQueryService/momqueryservice.py b/SAS/MoM/MoMQueryService/momqueryservice.py index bfe2c7cfb52..d7d541d5c27 100755 --- a/SAS/MoM/MoMQueryService/momqueryservice.py +++ b/SAS/MoM/MoMQueryService/momqueryservice.py @@ -80,8 +80,11 @@ class MoMDatabaseWrapper: # try a simple select # if it fails, reconnect cursor = self.conn.cursor() - cursor.execute('''SELECT * FROM project;''') - cursor.fetchall() + cursor.execute('''SELECT id FROM project;''') + if len(cursor.fetchall()) == 0: + logger.warning('unexpected answer while checking connection. reconnecting in 1 sec...') + time.sleep(1) + self._connect() except (OperationalError, AttributeError) as e: if isinstance(e, OperationalError): logger.error(str(e)) -- GitLab