-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Patch BigQueryClient to retry on network error #3088
Conversation
At the moment sometimes long jobs can cause the BigQueryClient to timeout since the connection is created at initialisation of the target. This patch retries by re-creating the client object if it fails (up to a retry limit), so that the client will not be timed out when calling `complete()` on the BigQueryTarget after a long job.
luigi/contrib/bigquery.py
Outdated
except (TimeoutError, BrokenPipeError, IOError) as bq_connection_error: | ||
if self.retry_count > self.retry_limit: | ||
raise Exception(f"Exceeded max retries for BigQueryClient connection error: {bq_connection_error}") from bq_connection_error | ||
self.retry_count += 1 | ||
self.__initialise_client() | ||
self.dataset_exists(dataset) |
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.
How about using retry decorator to simplify the codes?
The implementation below will be helpful.
https://github.com/spotify/luigi/blob/master/luigi/contrib/gcs.py#L72-L81
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.
Thanks, I'll make that change.
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.
@jamesmcm Thank you! Looks good to me, but flake8 notifies some formatting problems.
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.
Thanks, I fixed that too.
Note the use of the after lambda function to re-create the client if the connection fails
This PR looks great! |
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.
lgtm
Description
This patch retries by re-creating the client object if it fails (up to a retry limit), so that the client will not be timed out when calling
complete()
on the BigQueryTarget after a long job.Motivation and Context
At the moment sometimes long jobs can cause the BigQueryClient to timeout since the connection is created at initialisation of the target.
Have you tested this? If so, how?
Yes, passing this patched client worked for jobs that would have timeout issues previously.