Skip to content

Commit

Permalink
improved resiliency logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yorek committed Mar 23, 2020
1 parent f155f67 commit be746b5
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __getConnection(self):
def __removeConnection(self):
self.__connection = None

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

cursor.commit()
except pyodbc.Error as e:
if isinstance(e, pyodbc.ProgrammingError) or isinstance(e, pyodbc.OperationalError):
app.logger.error(f"{e.args[1]}")
if e.args[0] == "08S01":
# If there is a "Communication Link Failure" error,
# then connection must be removed
# as it will be in an invalid state
self.__removeConnection()
raise
except pyodbc.OperationalError as e:
app.logger.error(f"{e.args[1]}")
if e.args[0] == "08S01":
# If there is a "Communication Link Failure" error,
# then connection must be removed
# as it will be in an invalid state
self.__removeConnection()
raise
finally:
cursor.close()

Expand Down

0 comments on commit be746b5

Please sign in to comment.