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 google.api.core.timeout #3858

Merged
merged 5 commits into from
Aug 24, 2017
Merged

Conversation

theacodes
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 23, 2017
@theacodes theacodes added api: core and removed cla: yes This human has signed the Contributor License Agreement. labels Aug 23, 2017
@theacodes
Copy link
Contributor Author

Towards #3842

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 23, 2017
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.

Mostly LGTM


for n in range(10):
try:
is_thing_ready({'example': 'data'})

This comment was marked as spam.

This comment was marked as spam.

_DEFAULT_INITIAL_TIMEOUT = 5.0 # seconds
_DEFAULT_MAXIMUM_TIMEOUT = 30.0 # seconds
_DEFAULT_TIMEOUT_MULTIPLIER = 2.0
_DEFAULT_DEADLINE = None # seconds

This comment was marked as spam.

This comment was marked as spam.

Yields:
float: A timeout value.
"""
if deadline is not None:

This comment was marked as spam.

This comment was marked as spam.

datetime_helpers.utcnow() +
datetime.timedelta(seconds=deadline))
else:
deadline = datetime.datetime.max

This comment was marked as spam.

This comment was marked as spam.


@six.python_2_unicode_compatible
class ExponentialTimeout(object):
"""A decorator that adds a exponentially increasing timeout argument.

This comment was marked as spam.

This comment was marked as spam.

@six.wraps(func)
def func_with_timeout(*args, **kwargs):
"""Wrapped function that adds timeout."""
kwargs['timeout'] = next(timeouts)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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.

LGTM

@theacodes theacodes merged commit 7cda5dd into googleapis:master Aug 24, 2017
@theacodes theacodes deleted the api-core-timeout branch August 24, 2017 18:01
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