Skip to content

Commit be78a96

Browse files
authored
Add 'retry' argument to '_AsyncJob.result'. (googleapis#6302)
Pass it through to the '_begin' call. Note that we need to modify the 'api_core...PollingFuture' class before we can safely pass the 'retry' through to its 'result'.
1 parent d0a3a7e commit be78a96

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

bigquery/google/cloud/bigquery/job.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,17 @@ def done(self, retry=DEFAULT_RETRY):
678678
self.reload(retry=retry)
679679
return self.state == _DONE_STATE
680680

681-
def result(self, timeout=None):
681+
def result(self, timeout=None, retry=DEFAULT_RETRY):
682682
"""Start the job and wait for it to complete and get the result.
683683
684684
:type timeout: float
685685
:param timeout:
686686
How long (in seconds) to wait for job to complete before raising
687687
a :class:`concurrent.futures.TimeoutError`.
688688
689+
:type retry: :class:`google.api_core.retry.Retry`
690+
:param retry: (Optional) How to retry the RPC.
691+
689692
:rtype: _AsyncJob
690693
:returns: This instance.
691694
@@ -695,7 +698,7 @@ def result(self, timeout=None):
695698
not complete in the given timeout.
696699
"""
697700
if self.state is None:
698-
self._begin()
701+
self._begin(retry=retry)
699702
# TODO: modify PollingFuture so it can pass a retry argument to done().
700703
return super(_AsyncJob, self).result(timeout=timeout)
701704

bigquery/tests/unit/test_job.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,13 +789,27 @@ def test_done_already(self):
789789

790790
@mock.patch("google.api_core.future.polling.PollingFuture.result")
791791
def test_result_default_wo_state(self, result):
792+
from google.cloud.bigquery.retry import DEFAULT_RETRY
793+
792794
client = _make_client(project=self.PROJECT)
793795
job = self._make_one(self.JOB_ID, client)
794796
begin = job._begin = mock.Mock()
795797

796798
self.assertIs(job.result(), result.return_value)
797799

798-
begin.assert_called_once()
800+
begin.assert_called_once_with(retry=DEFAULT_RETRY)
801+
result.assert_called_once_with(timeout=None)
802+
803+
@mock.patch('google.api_core.future.polling.PollingFuture.result')
804+
def test_result_w_retry_wo_state(self, result):
805+
client = _make_client(project=self.PROJECT)
806+
job = self._make_one(self.JOB_ID, client)
807+
begin = job._begin = mock.Mock()
808+
retry = mock.Mock()
809+
810+
self.assertIs(job.result(retry=retry), result.return_value)
811+
812+
begin.assert_called_once_with(retry=retry)
799813
result.assert_called_once_with(timeout=None)
800814

801815
@mock.patch("google.api_core.future.polling.PollingFuture.result")

0 commit comments

Comments
 (0)