Skip to content

Commit

Permalink
Move break
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfriedman6 committed Nov 22, 2024
1 parent 03b6bdd commit 9538159
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/nypl_py_utils/classes/mysql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ def connect(self, retry_count=0, backoff_factor=5, **kwargs):
user=self.user,
password=self.password,
**kwargs)
break
except (mysql.connector.Error):
if attempt_count < retry_count:
self.logger.info('Failed to connect -- retrying')
time.sleep(backoff_factor ** attempt_count)
attempt_count += 1
else:
raise
else:
break
except Exception as e:
self.logger.error(
'Error connecting to {name} database: {error}'.format(
Expand Down
3 changes: 1 addition & 2 deletions src/nypl_py_utils/classes/postgresql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def connect(self, retry_count=0, backoff_factor=5, **kwargs):
try:
try:
self.conn = psycopg.connect(self.conn_info, **kwargs)
break
except (psycopg.OperationalError,
psycopg.errors.ConnectionTimeout):
if attempt_count < retry_count:
Expand All @@ -46,8 +47,6 @@ def connect(self, retry_count=0, backoff_factor=5, **kwargs):
attempt_count += 1
else:
raise
else:
break
except Exception as e:
self.logger.error(
'Error connecting to {name} database: {error}'.format(
Expand Down
3 changes: 1 addition & 2 deletions src/nypl_py_utils/classes/redshift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ def connect(self, retry_count=0, backoff_factor=5):
user=self.user,
password=self.password,
sslmode='verify-full')
break
except (redshift_connector.InterfaceError):
if attempt_count < retry_count:
self.logger.info('Failed to connect -- retrying')
time.sleep(backoff_factor ** attempt_count)
attempt_count += 1
else:
raise
else:
break
except Exception as e:
self.logger.error(
'Error connecting to {name} database: {error}'.format(
Expand Down

0 comments on commit 9538159

Please sign in to comment.