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

feat(ingest/bigquery): Add query job retries for transient errors #11162

Merged
merged 9 commits into from
Aug 27, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from google.api_core import retry
from google.cloud import bigquery, datacatalog_v1, resourcemanager_v3
from google.cloud.bigquery import retry as bq_retry
from google.cloud.bigquery.table import (
RowIterator,
TableListItem,
Expand Down Expand Up @@ -155,8 +156,23 @@ def __init__(
self.datacatalog_client = datacatalog_client

def get_query_result(self, query: str) -> RowIterator:
def _should_retry(exc: BaseException) -> bool:
logger.debug(f"Exception occured for job query. Reason: {exc}")
# Jobs sometimes fail with transient errors.
# This is not currently handled by the python-bigquery client.
# https://github.com/googleapis/python-bigquery/issues/23
return "Retrying the job may solve the problem" in str(exc)

logger.debug(f"Query : {query}")
resp = self.bq_client.query(query)
resp = self.bq_client.query(
query,
job_retry=retry.Retry(
predicate=lambda exc: (
bq_retry.DEFAULT_JOB_RETRY._predicate(exc) or _should_retry(exc)
),
deadline=bq_retry.DEFAULT_JOB_RETRY._deadline,
),
)
return resp.result()

def get_projects(self, max_results_per_page: int = 100) -> List[BigqueryProject]:
Expand Down
Loading