From 45d3e2df601d64181d480818205e09259bdd4e1d Mon Sep 17 00:00:00 2001 From: Sean Glynn Date: Tue, 10 May 2022 09:51:29 +0100 Subject: [PATCH] Adding retry function --- target_bigquery/db_sync.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/target_bigquery/db_sync.py b/target_bigquery/db_sync.py index d487c43..780aa98 100644 --- a/target_bigquery/db_sync.py +++ b/target_bigquery/db_sync.py @@ -15,6 +15,11 @@ from target_bigquery.stream_ref_helper import StreamRefHelper from target_bigquery import sql_utils +from google.api_core.future import polling +from google.cloud import bigquery +from google.cloud.bigquery import retry as bq_retry + + logger = singer.get_logger() PRECISION = 38 @@ -288,7 +293,9 @@ def to_query_parameter(value): queries = [query] logger.info("TARGET_BIGQUERY - Running query: {}".format(query)) - query_job = self.client.query(';\n'.join(queries), job_config=job_config) + + query_job = self.client.query(';\n'.join(queries), job_config=job_config, retry=bq_retry.DEFAULT_RETRY) + query_job._retry = polling.DEFAULT_RETRY query_job.result() return query_job @@ -460,6 +467,7 @@ def create_schema_if_not_exists(self): self.grant_privilege(schema, self.grantees, self.grant_usage_on_schema) except Conflict: # Already exists. + pass # pylint: disable=no-self-use