-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add operation future #3618
Add operation future #3618
Conversation
|
||
Args: | ||
operation (dict): Operation as a dictionary. | ||
api_request (Callable): A callable used to make an API request. This |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine to me. No issues adding tenacity
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High-level: Do LRO RPC services give trailers describing when to retry?
@@ -57,6 +57,7 @@ | |||
'google-auth >= 0.4.0, < 2.0.0dev', | |||
'google-auth-httplib2', | |||
'six', | |||
'tenacity >= 4.0.0, <5.0.0dev' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -15,8 +15,10 @@ | |||
"""Abstract and helper bases for Future implementations.""" | |||
|
|||
import abc | |||
import concurrent.futures |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/cloud/future/base.py
Outdated
@@ -72,8 +74,9 @@ def set_exception(self, exception): | |||
class PollingFuture(Future): | |||
"""A Future that needs to poll some service to check its status. | |||
|
|||
The private :meth:`_blocking_poll` method should be implemented by | |||
subclasses. | |||
The private :meth:`done` method should be implemented by |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def _blocking_poll(self, timeout=None): | ||
"""Poll and wait for the Future to be resolved. | ||
|
||
Args: | ||
timeout (int): How long to wait for the operation to complete. | ||
If None, wait indefinitely. | ||
""" | ||
# pylint: disable=missing-raises | ||
raise NotImplementedError() | ||
if self._result_set: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/cloud/future/base.py
Outdated
if self._result_set: | ||
return | ||
|
||
retry_on = tenacity.retry_if_result(lambda result: result is not True) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self.set_exception(exception) | ||
else: | ||
exception = exceptions.GoogleCloudError( | ||
'Unknown operation error') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
bool: True if the operation is complete, False otherwise. | ||
""" | ||
operation = self._refresh_and_update() | ||
return operation.done |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
Args: | ||
operation (dict): Operation as a dictionary. | ||
api_request (Callable): A callable used to make an API request. This |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Args: | ||
operation (dict): Operation as a dictionary. | ||
api_request (Callable): A callable used to make an API request. This | ||
should generally be an instance of |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
to a given API) vis `HTTP/JSON`_. | ||
|
||
.. _HTTP/JSON: https://cloud.google.com/speech/reference/rest/\ | ||
v1beta1/operations#Operation |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -94,7 +92,8 @@ def _set_result_from_operation(self): | |||
self.set_exception(exception) | |||
else: | |||
exception = exceptions.GoogleCloudError( | |||
'Unknown operation error') | |||
'Unexpected state: Long-running operation had neither ' | |||
'response nor error set.') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dhermes the latest release of resumable-media seems to have broken circle. Do you want me to hold off on merging this until you can resolve that? (Master will be broken by it either way). |
Rebased and waiting on CI to merge. |
Note: This adds a dependency on the
tenacity
library. It's worth it.Towards #3617