Skip to content
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

Merged
merged 4 commits into from
Jul 19, 2017
Merged

Add operation future #3618

merged 4 commits into from
Jul 19, 2017

Conversation

theacodes
Copy link
Contributor

Note: This adds a dependency on the tenacity library. It's worth it.

Towards #3617

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 17, 2017

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.

Copy link
Contributor

@lukesneeringer lukesneeringer left a 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.

Copy link
Contributor

@dhermes dhermes left a 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.

@@ -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.

@@ -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.

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.

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.

self.set_exception(exception)
else:
exception = exceptions.GoogleCloudError(
'Unknown operation error')

This comment was marked as spam.

This comment was marked as spam.

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.


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.

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.

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.

@@ -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.

@theacodes
Copy link
Contributor Author

@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).

@theacodes
Copy link
Contributor Author

Rebased and waiting on CI to merge.

@theacodes theacodes merged commit c565801 into googleapis:master Jul 19, 2017
@theacodes theacodes deleted the future branch July 19, 2017 16:41
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 21, 2017
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: core cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants