22
33from google .api_core .future .polling import DEFAULT_POLLING
44from google .api_core .retry import Retry
5- from google .cloud .bigquery .retry import DEFAULT_RETRY , _job_should_retry
5+ from google .cloud .bigquery .retry import DEFAULT_JOB_RETRY , _job_should_retry
66from requests .exceptions import ConnectionError
77
88from dbt .adapters .contracts .connection import Connection , ConnectionState
1515
1616_logger = AdapterLogger ("BigQuery" )
1717
18-
19- _SECOND = 1.0
20- _MINUTE = 60 * _SECOND
21- _HOUR = 60 * _MINUTE
22- _DAY = 24 * _HOUR
23- _DEFAULT_INITIAL_DELAY = _SECOND
24- _DEFAULT_MAXIMUM_DELAY = 3 * _SECOND
25- _DEFAULT_POLLING_MAXIMUM_DELAY = 10 * _SECOND
18+ _MINUTE = 60.0
19+ _DAY = 24 * 60 * 60.0
2620
2721
2822class RetryFactory :
@@ -44,7 +38,7 @@ def create_job_execution_timeout(self, fallback: float = _DAY) -> float:
4438 ) # keep _DAY here so it's not overridden by passing fallback=None
4539
4640 def create_retry (self , fallback : Optional [float ] = None ) -> Retry :
47- return DEFAULT_RETRY .with_timeout (self ._job_execution_timeout or fallback or _DAY )
41+ return DEFAULT_JOB_RETRY .with_timeout (self ._job_execution_timeout or fallback or _DAY )
4842
4943 def create_polling (self , model_timeout : Optional [float ] = None ) -> Retry :
5044 return DEFAULT_POLLING .with_timeout (model_timeout or self ._job_execution_timeout or _DAY )
@@ -53,14 +47,21 @@ def create_reopen_with_deadline(self, connection: Connection) -> Retry:
5347 """
5448 This strategy mimics what was accomplished with _retry_and_handle
5549 """
56- return Retry (
57- predicate = _DeferredException (self ._retries ),
58- initial = _DEFAULT_INITIAL_DELAY ,
59- maximum = _DEFAULT_MAXIMUM_DELAY ,
60- deadline = self ._job_deadline ,
61- on_error = _create_reopen_on_error (connection ),
50+
51+ retry = DEFAULT_JOB_RETRY .with_delay (maximum = 3.0 ).with_predicate (
52+ _DeferredException (self ._retries )
6253 )
6354
55+ # there is no `with_on_error` method, but we want to retain the defaults on `DEFAULT_JOB_RETRY
56+ retry ._on_error = _create_reopen_on_error (connection )
57+
58+ # don't override the default deadline to None if the user did not provide one,
59+ # the process will never end
60+ if deadline := self ._job_deadline :
61+ return retry .with_deadline (deadline )
62+
63+ return retry
64+
6465
6566class _DeferredException :
6667 """
0 commit comments