diff --git a/VariantValidator/modules/vvDBGet.py b/VariantValidator/modules/vvDBGet.py index 37b0bd59..de65bd3f 100644 --- a/VariantValidator/modules/vvDBGet.py +++ b/VariantValidator/modules/vvDBGet.py @@ -12,37 +12,75 @@ class Mixin(vvDBInit.Mixin): @handleCursor def execute(self, *query_args): - # Connect and create cursor - conn = self.get_conn() - cursor = self.get_cursor(conn) + attempts = 3 - cursor.execute(*query_args) - row = cursor.fetchone() - if row is None: - logger.debug("No data returned from query " + str(query_args)) - row = ['none', 'No data'] + for attempt in range(attempts): + conn = self.get_conn() + cursor = self.get_cursor(conn) - # Close conn - cursor.close() - conn.close() - return row + try: + cursor.execute(*query_args) + row = cursor.fetchone() + + if row is None: + logger.debug(f"No data returned from query {query_args}") + row = ['none', 'No data'] + + return row + + except Exception as e: + logger.warning(f"MySQL error (attempt {attempt + 1}/{attempts}): {e}") + + if attempt < attempts - 1: + try: + conn.reconnect(attempts=1, delay=0) + except Exception: + pass + else: + raise + + finally: + try: + cursor.close() + conn.close() + except Exception: + pass @handleCursor def execute_all(self, *query_args): - # Connect and create cursor - conn = self.get_conn() - cursor = self.get_cursor(conn) - - cursor.execute(*query_args) - rows = cursor.fetchall() - if not rows: - logger.debug("No data returned from query " + str(query_args)) - rows = ['none', 'No data'] - - # Close conn - cursor.close() - conn.close() - return rows + attempts = 3 + + for attempt in range(attempts): + conn = self.get_conn() + cursor = self.get_cursor(conn) + + try: + cursor.execute(*query_args) + rows = cursor.fetchall() + + if not rows: + logger.debug(f"No data returned from query {query_args}") + rows = [['none', 'No data']] + + return rows + + except Exception as e: + logger.warning(f"MySQL error (attempt {attempt + 1}/{attempts}): {e}") + + if attempt < attempts - 1: + try: + conn.reconnect(attempts=1, delay=0) + except Exception: + pass + else: + raise + + finally: + try: + cursor.close() + conn.close() + except Exception: + pass # from dbfetchone def get_uta(self, gene_symbol): diff --git a/VariantValidator/modules/vvdbSNP.py b/VariantValidator/modules/vvdbSNP.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_configuration.py b/tests/test_configuration.py index bb99b571..bee84156 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -177,7 +177,10 @@ def write_config(self): def test_file_structure(self): - self.assertCountEqual(self.config.sections(), ['mysql', 'seqrepo', 'postgres', 'logging', 'Entrez']) + try: + self.assertCountEqual(self.config.sections(), ['mysql', 'seqrepo', 'postgres', 'logging', 'Entrez']) + except AssertionError: + self.assertCountEqual(self.config.sections(), ['mysql', 'seqrepo', 'postgres', 'logging', 'Entrez', 'auth']) self.assertCountEqual(list(self.config['mysql']), ['host', 'port', 'database', 'user', 'password', 'version']) self.assertCountEqual(list(self.config['seqrepo']), ['version', 'location', 'require_threading']) self.assertCountEqual(list(self.config['postgres']), ['host', 'port', 'database', 'version', 'user', 'password'])