Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zwright authored Oct 2, 2024
2 parents 2e9619a + 50f5ee1 commit 90d5390
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
logger = logging.getLogger("atlas-file-service")
logging.basicConfig(level=logging.ERROR)


class MYSQLConnection:
def __init__(self):
logger.info(
Expand All @@ -51,15 +52,21 @@ def __init__(self):
"Can't load environment variables from docker... trying local .env file instead...", connectError
)

def get_db_cursor(self):
def get_db_cursor(self, connect_try=0):
try:
if (self.database.is_connected() == False):
self.get_db_connection();
self.cursor = self.database.cursor(buffered=False, dictionary=True)
return self.cursor
except Exception as error:
logger.error("Can't get mysql cursor", error)
os.sys.exit()
if connect_try < 5:
logger.info("Can't get cursor. Trying to reconnect to the database.")
connect_try = connect_try + 1
self.get_db_connection()
return self.get_db_cursor(connect_try)
else:
logger.error("Tried too many times to get mysql cursor. Exiting.", error)
os.sys.exit()

def get_db_connection(self):
try:
Expand All @@ -69,6 +76,7 @@ def get_db_connection(self):
port=self.port,
password=self.password,
database=self.database_name,
pool_name="atlas-file-service"
)
self.database.get_warnings = True
return self.database
Expand Down Expand Up @@ -139,4 +147,3 @@ def downloadDerivedFileS3PS(packageId, objectName):
logger.error(error)
except botocore.exceptions.ParamValidationError as error:
logger.error(error)

0 comments on commit 90d5390

Please sign in to comment.