-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add patron data methods and database connection retries #39
Conversation
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
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).