Skip to content

Commit be746b5

Browse files
committed
improved resiliency logic
1 parent f155f67 commit be746b5

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Diff for: app.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __getConnection(self):
4949
def __removeConnection(self):
5050
self.__connection = None
5151

52-
@retry(stop=stop_after_attempt(3), wait=wait_fixed(10), retry=retry_if_exception_type(pyodbc.Error), after=after_log(app.logger, logging.DEBUG))
52+
@retry(stop=stop_after_attempt(3), wait=wait_fixed(10), retry=retry_if_exception_type(pyodbc.OperationalError), after=after_log(app.logger, logging.DEBUG))
5353
def executeQueryJSON(self, procedure, payload=None):
5454
result = {}
5555
try:
@@ -70,15 +70,14 @@ def executeQueryJSON(self, procedure, payload=None):
7070
result = {}
7171

7272
cursor.commit()
73-
except pyodbc.Error as e:
74-
if isinstance(e, pyodbc.ProgrammingError) or isinstance(e, pyodbc.OperationalError):
75-
app.logger.error(f"{e.args[1]}")
76-
if e.args[0] == "08S01":
77-
# If there is a "Communication Link Failure" error,
78-
# then connection must be removed
79-
# as it will be in an invalid state
80-
self.__removeConnection()
81-
raise
73+
except pyodbc.OperationalError as e:
74+
app.logger.error(f"{e.args[1]}")
75+
if e.args[0] == "08S01":
76+
# If there is a "Communication Link Failure" error,
77+
# then connection must be removed
78+
# as it will be in an invalid state
79+
self.__removeConnection()
80+
raise
8281
finally:
8382
cursor.close()
8483

0 commit comments

Comments
 (0)