Skip to content
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
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions parsons/google/google_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -464,7 +467,7 @@ def copy_from_gcs(
job_config=job_config,
**load_kwargs,
)
load_job.result()
load_job.result(timeout=MAX_TIMEOUT)
Copy link
Collaborator

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.

Copy link
Author

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

except exceptions.BadRequest as e:
if "one of the files is larger than the maximum allowed size." in str(e):
logger.debug(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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(
Expand Down
Loading