Skip to content

Commit

Permalink
Adds backoff on request and fixes missing variable update (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmesel authored Dec 6, 2023
1 parent 0ae8964 commit 9cc1cfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
singer-python~=5.12.1
google-cloud-bigquery==2.26.0
google-cloud-bigquery==2.34.3
jsonschema~=2.6.0
setuptools~=60.3.1
pendulum
pendulum
backoff
11 changes: 9 additions & 2 deletions target_bigquery/processhandler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
import uuid
import backoff
import singer

from datetime import datetime
from tempfile import TemporaryFile

import singer
from google.api_core import exceptions as google_exceptions
from google.cloud import bigquery
from google.cloud.bigquery import LoadJobConfig, CopyJobConfig, QueryJobConfig
Expand Down Expand Up @@ -252,6 +254,11 @@ def primary_key_condition(self, stream):
#TODO: test it with multiple ids (an array of ids, if there are multiple key_properties in JSON schema)
#TODO: test it with dupe ids in the data

@backoff.on_exception(
backoff.expo,
google_exceptions.BadRequest,
max_tries=3
)
def _do_temp_table_based_load(self, rows):
assert isinstance(rows, dict)

Expand Down Expand Up @@ -324,7 +331,7 @@ def _do_temp_table_based_load(self, rows):

except NotFound:
self.logger.info(f"Table {table_id} is not found, proceeding to upload with TRUNCATE")
self.truncate = True
instance_truncate = True

if not incremental_success:
copy_config = CopyJobConfig()
Expand Down

0 comments on commit 9cc1cfc

Please sign in to comment.