File tree 3 files changed +35
-6
lines changed
3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -66,9 +66,12 @@ def __init__(self, retry=DEFAULT_RETRY):
66
66
self ._done_callbacks = []
67
67
68
68
@abc .abstractmethod
69
- def done (self ):
69
+ def done (self , retry = DEFAULT_RETRY ):
70
70
"""Checks to see if the operation is complete.
71
71
72
+ Args:
73
+ retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
74
+
72
75
Returns:
73
76
bool: True if the operation is complete, False otherwise.
74
77
"""
Original file line number Diff line number Diff line change @@ -145,21 +145,28 @@ def _set_result_from_operation(self):
145
145
)
146
146
self .set_exception (exception )
147
147
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
+ """
150
154
# If the currently cached operation is done, no need to make another
151
155
# RPC as it will not change once done.
152
156
if not self ._operation .done :
153
- self ._operation = self ._refresh ()
157
+ self ._operation = self ._refresh (retry = retry )
154
158
self ._set_result_from_operation ()
155
159
156
- def done (self ):
160
+ def done (self , retry = polling . DEFAULT_RETRY ):
157
161
"""Checks to see if the operation is complete.
158
162
163
+ Args:
164
+ retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
165
+
159
166
Returns:
160
167
bool: True if the operation is complete, False otherwise.
161
168
"""
162
- self ._refresh_and_update ()
169
+ self ._refresh_and_update (retry )
163
170
return self ._operation .done
164
171
165
172
def cancel (self ):
Original file line number Diff line number Diff line change 15
15
16
16
import mock
17
17
18
+ from google .api_core import exceptions
18
19
from google .api_core import operation
19
20
from google .api_core import operations_v1
21
+ from google .api_core import retry
20
22
from google .longrunning import operations_pb2
21
23
from google .protobuf import struct_pb2
22
24
from google .rpc import code_pb2
@@ -113,6 +115,23 @@ def test_result():
113
115
assert future .done ()
114
116
115
117
118
+ def test_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
+
116
135
def test_exception ():
117
136
expected_exception = status_pb2 .Status (message = "meep" )
118
137
responses = [
You can’t perform that action at this time.
0 commit comments