8000 BigQuery: add 'retry' argument to '_AsyncJob.result'. by tseaver · Pull Request #6302 · googleapis/google-cloud-python · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,17 @@ def done(self, retry=DEFAULT_RETRY):
self.reload(retry=retry)
return self.state == _DONE_STATE

def result(self, timeout=None):
def result(self, timeout=None, retry=DEFAULT_RETRY):
"""Start the job and wait for it to complete and get the result.

:type timeout: float
:param timeout:
How long (in seconds) to wait for job to complete before raising
a :class:`concurrent.futures.TimeoutError`.

:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.

:rtype: _AsyncJob
:returns: This instance.

Expand All @@ -694,7 +697,7 @@ def result(self, timeout=None):
not complete in the given timeout.
"""
if self.state is None:
self._begin()
self._begin(retry=retry)
# TODO: modify PollingFuture so it can pass a retry argument to done().
return super(_AsyncJob, self).result(timeout=timeout)

Expand Down
16 changes: 15 additions & 1 deletion bigquery/tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,27 @@ def test_done_already(self):

@mock.patch('google.api_core.future.polling.PollingFuture.result')
def test_result_default_wo_state(self, result):
from google.cloud.bigquery.retry import DEFAULT_RETRY

client = _make_client(project=self.PROJECT)
job = self._make_one(self.JOB_ID, client)
begin = job._begin = mock.Mock()

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

begin.assert_called_once()
begin.assert_called_once_with(retry=DEFAULT_RETRY)
result.assert_called_onc 61C1 e_with(timeout=None)

@mock.patch('google.api_core.future.polling.PollingFuture.result')
def test_result_w_retry_wo_state(self, result):
client = _make_client(project=self.PROJECT)
job = self._make_one(self.JOB_ID, client)
begin = job._begin = mock.Mock()
retry = mock.Mock()

self.assertIs(job.result(retry=retry), result.return_value)

begin.assert_called_once_with(retry=retry)
result.assert_called_once_with(timeout=None)

@mock.patch('google.api_core.future.polling.PollingFuture.result')
Expand Down
0