Skip to content

Conversation

@aaronfriedman6
Copy link
Contributor

@aaronfriedman6 aaronfriedman6 commented Nov 20, 2024

See CHANGELOG for more information. Most of the existing DE pipelines use one of the methods in patron_data_helper, so a followup to this PR will be replacing all of that code. Note that the database work (the first commit) is unrelated to the patron data work (the second commit).

Comment on lines 37 to 62
while attempt_count <= retry_count:
try:
try:
self.conn = mysql.connector.connect(
host=self.host,
port=self.port,
database=self.database,
user=self.user,
password=self.password,
**kwargs)
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(
name=self.database, error=e))
raise MySQLClientError(
'Error connecting to {name} database: {error}'.format(
name=self.database, error=e)) from None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit & I'm not sure how to fix this, but this try-except block is quite nested and not super readable -- is there a way around this? I see what you're trying to do / it makes sense, but I think there is a way around the additional else on line 54

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a little convoluted -- the idea was I only wanted to have to log and raise the ClientError once and I also wanted non-database Exceptions to still get thrown immediately. I moved the break to within the try block -- hopefully that makes it at least a little better?

fatimarahman
fatimarahman previously approved these changes Nov 22, 2024
@aaronfriedman6 aaronfriedman6 merged commit f9f5746 into main Nov 22, 2024
2 checks passed
@aaronfriedman6 aaronfriedman6 deleted the patron-data-methods branch November 22, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants