-
Notifications
You must be signed in to change notification settings - Fork 132
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
Issue 910 - Added timeout to BigQuery load_job.result() #981
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,9 @@ | |
# 100k rows per batch at ~1k bytes each = ~100MB per batch. | ||
QUERY_BATCH_SIZE = 100000 | ||
|
||
# Max number of seconds to wait for a request before raising a timeout error | ||
MAX_TIMEOUT = 30 | ||
|
||
|
||
def get_table_ref(client, table_name): | ||
# Helper function to build a TableReference for our table | ||
|
@@ -464,7 +467,7 @@ def copy_from_gcs( | |
job_config=job_config, | ||
**load_kwargs, | ||
) | ||
load_job.result() | ||
load_job.result(timeout=MAX_TIMEOUT) | ||
except exceptions.BadRequest as e: | ||
if "one of the files is larger than the maximum allowed size." in str(e): | ||
logger.debug( | ||
|
@@ -504,6 +507,10 @@ def copy_from_gcs( | |
else: | ||
raise e | ||
|
||
except exceptions.DeadlineExceeded as e: | ||
logger.error(f"Max timeout exceeded for {gcs_blob_uri.split('/')[-1]}") | ||
raise e | ||
|
||
def copy_large_compressed_file_from_gcs( | ||
self, | ||
gcs_blob_uri: str, | ||
|
@@ -632,7 +639,10 @@ def copy_large_compressed_file_from_gcs( | |
job_config=job_config, | ||
**load_kwargs, | ||
) | ||
load_job.result() | ||
load_job.result(timeout=MAX_TIMEOUT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment |
||
except exceptions.DeadlineExceeded as e: | ||
logger.error(f"Max timeout exceeded for {gcs_blob_uri.split('/')[-1]}") | ||
raise e | ||
finally: | ||
if uncompressed_gcs_uri: | ||
new_bucket_name, new_blob_name = gcs.split_uri( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Instead of using a constant, perhaps this should be a keyword parameter that defaults to 30. Something like:
def get_table_ref(client, table_name, timeout = 30):
That way if 30 isn't enough for my use case, or is too long, I can adapt the behavior.
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.
Hi, for sure! I think that is a cleaner implementation, good suggestion