Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit14f1f34

Browse files
Gurov Ilyabusunkim96
Gurov Ilya
authored andcommitted
feat(api_core): add retry param into PollingFuture() and it's inheritors (#9923)
* feat(api_core): add retry param into PollingFuture() and it's inheritorsTowards #6197
1 parent18375fb commit14f1f34

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

‎google/api_core/future/polling.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ def __init__(self, retry=DEFAULT_RETRY):
6666
self._done_callbacks= []
6767

6868
@abc.abstractmethod
69-
defdone(self):
69+
defdone(self,retry=DEFAULT_RETRY):
7070
"""Checks to see if the operation is complete.
7171
72+
Args:
73+
retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
74+
7275
Returns:
7376
bool: True if the operation is complete, False otherwise.
7477
"""

‎google/api_core/operation.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,28 @@ def _set_result_from_operation(self):
145145
)
146146
self.set_exception(exception)
147147

148-
def_refresh_and_update(self):
149-
"""Refresh the operation and update the result if needed."""
148+
def_refresh_and_update(self,retry=polling.DEFAULT_RETRY):
149+
"""Refresh the operation and update the result if needed.
150+
151+
Args:
152+
retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
153+
"""
150154
# If the currently cached operation is done, no need to make another
151155
# RPC as it will not change once done.
152156
ifnotself._operation.done:
153-
self._operation=self._refresh()
157+
self._operation=self._refresh(retry=retry)
154158
self._set_result_from_operation()
155159

156-
defdone(self):
160+
defdone(self,retry=polling.DEFAULT_RETRY):
157161
"""Checks to see if the operation is complete.
158162
163+
Args:
164+
retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
165+
159166
Returns:
160167
bool: True if the operation is complete, False otherwise.
161168
"""
162-
self._refresh_and_update()
169+
self._refresh_and_update(retry)
163170
returnself._operation.done
164171

165172
defcancel(self):

‎tests/unit/test_operation.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
importmock
1717

18+
fromgoogle.api_coreimportexceptions
1819
fromgoogle.api_coreimportoperation
1920
fromgoogle.api_coreimportoperations_v1
21+
fromgoogle.api_coreimportretry
2022
fromgoogle.longrunningimportoperations_pb2
2123
fromgoogle.protobufimportstruct_pb2
2224
fromgoogle.rpcimportcode_pb2
@@ -113,6 +115,23 @@ def test_result():
113115
assertfuture.done()
114116

115117

118+
deftest_done_w_retry():
119+
RETRY_PREDICATE=retry.if_exception_type(exceptions.TooManyRequests)
120+
test_retry=retry.Retry(predicate=RETRY_PREDICATE)
121+
122+
expected_result=struct_pb2.Struct()
123+
responses= [
124+
make_operation_proto(),
125+
# Second operation response includes the result.
126+
make_operation_proto(done=True,response=expected_result),
127+
]
128+
future,_,_=make_operation_future(responses)
129+
future._refresh=mock.Mock()
130+
131+
future.done(retry=test_retry)
132+
future._refresh.assert_called_once_with(retry=test_retry)
133+
134+
116135
deftest_exception():
117136
expected_exception=status_pb2.Status(message="meep")
118137
responses= [

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp