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

AsyncIO Integration [Part 1] #26

Merged
merged 1 commit into from May 27, 2020
Merged

Conversation

lidizheng
Copy link
Contributor

Since the PR in microgenerator is pretty stable, the existing set of AsyncIO features should be sufficient to support generated code. I plan to split the AsyncIO integration into 3 parts (please let me know if anything I can do to help review): utility modules, LRO related modules, grpc helpers modules.

This PR contains following changes:

  • Nox configuration
  • AsyncIO retry module
  • AsyncIO config parsing module
  • Exception parsing patch
  • Corresponding unit tests

Related #23

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 23, 2020
@lidizheng lidizheng force-pushed the aio-part-1 branch 2 times, most recently from 997a7b5 to 0f9b66f Compare April 23, 2020 21:39
@lidizheng lidizheng marked this pull request as ready for review April 23, 2020 22:42
@lidizheng
Copy link
Contributor Author

@busunkim96 PTAL.

Copy link
Contributor

@busunkim96 busunkim96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. At some point the docs will need to be updated to include the new classes (https://github.com/googleapis/python-api-core/tree/master/docs). Does it make more sense to do that now or to wait for other parts to be added?

@@ -0,0 +1,397 @@
# Copyright 2017 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright 2017 Google LLC
# Copyright 2020 Google LLC

tests/asyncio/gapic/test_config_async.py Outdated Show resolved Hide resolved
@lidizheng
Copy link
Contributor Author

@busunkim96 I will add doc in a separate PR. It might be better to update the doc for all new classes once.

@lidizheng lidizheng force-pushed the aio-part-1 branch 2 times, most recently from 4589485 to 97fa36c Compare April 28, 2020 18:39
@lidizheng
Copy link
Contributor Author

@busunkim96 PTAL at the doc gen code.

After checking the doc generation code, I found you are using Sphinx so it actually is easy to add docs alone the code. So, I will try to add docs templates with code in following PRs.

Copy link
Contributor

@software-dov software-dov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests look great, just had some nits to pick.

google/api_core/gapic_v1/__init__.py Outdated Show resolved Hide resolved
google/api_core/retry_async.py Outdated Show resolved Hide resolved
google/api_core/retry_async.py Outdated Show resolved Hide resolved
google/api_core/retry_async.py Outdated Show resolved Hide resolved
Args:
target(Callable): The function to call and retry. This must be a
nullary function - apply arguments with `functools.partial`.
predicate (Callable[Exception]): A callable used to determine if an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a name other than 'predicate' would be more helpful. I like the lisp convention of naming predicates with a -p tail; maybe is_retryable_p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function signature is mimicking the sync version, so we have consistent naming between two versions. I can change if you feel strongly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too strongly, especially if we're trying to preserve a convention.

google/api_core/retry_async.py Show resolved Hide resolved
google/api_core/retry_async.py Outdated Show resolved Hide resolved
Returns:
AsyncRetry: A new retry instance with the given deadline.
"""
return AsyncRetry(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worthwhile to add a replace method to AsyncRetry that takes optional parameters corresponding to the constructor params and returns a new AsyncRetry with the passed in overrides applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original designer of this class try to use the builder pattern. Naming each one with_* makes the application code more meaningful semantically. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine preserving the interfaces, but it seems like a lot of boilerplate for a common, straightforward desire: given an object, return a copy with specific fields updated. I think having a replace method that gets called by the with_deadline and with_predicate methods is still a net win.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to use a common _replace method. Thanks for the suggestion.

noxfile.py Outdated Show resolved Hide resolved
Comment on lines +67 to +73
assert retry._initial == 1.0
assert retry._multiplier == 2.5
assert retry._maximum == 120.0
assert retry._deadline == 600.0
assert timeout._initial == 120.0
assert timeout._multiplier == 1.0
assert timeout._maximum == 120.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not define an __eq__ method to handle all this boilerplate? The retry error predicate would still need to be tested by hand, but it would clean this bit up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain more about this comment? Do you mean an __eq__ method to compare a retry/timeout object and parsed JSON object?

Copy link
Contributor Author

@lidizheng lidizheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@software-dov Thanks for the detailed review. I definitely learned today. PTALA.

google/api_core/gapic_v1/__init__.py Outdated Show resolved Hide resolved
Args:
target(Callable): The function to call and retry. This must be a
nullary function - apply arguments with `functools.partial`.
predicate (Callable[Exception]): A callable used to determine if an
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function signature is mimicking the sync version, so we have consistent naming between two versions. I can change if you feel strongly.

google/api_core/retry_async.py Outdated Show resolved Hide resolved
google/api_core/retry_async.py Outdated Show resolved Hide resolved
google/api_core/retry_async.py Outdated Show resolved Hide resolved
google/api_core/retry_async.py Outdated Show resolved Hide resolved
google/api_core/retry_async.py Show resolved Hide resolved
Returns:
AsyncRetry: A new retry instance with the given deadline.
"""
return AsyncRetry(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original designer of this class try to use the builder pattern. Naming each one with_* makes the application code more meaningful semantically. WDYT?

google/api_core/retry_async.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
@lidizheng
Copy link
Contributor Author

BTW, I don't have the permission to merge PRs (and I don't have the full context of the release process). So, if there is any blocker, please let me know, no rush.

@busunkim96
Copy link
Contributor

@lidizheng There's nothing blocking the release since the changes are additive. Let's release this next week.

Thanks for all your work on this and @software-dov thank you for the thorough review. 😁

Copy link
Contributor

@software-dov software-dov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One minor issue, no need to repost if you don't think it's worth the hassle.

Returns:
AsyncRetry: A new retry instance with the given deadline.
"""
return AsyncRetry(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine preserving the interfaces, but it seems like a lot of boilerplate for a common, straightforward desire: given an object, return a copy with specific fields updated. I think having a replace method that gets called by the with_deadline and with_predicate methods is still a net win.

This change includes:
* Nox configuration support for AsynciO unit tests
    * No pre release gRPC Python required
* AsyncIO retry module
* AsyncIO config parsing module
* Exception parsing patch
* Corresponding unit test cases
@busunkim96 busunkim96 merged commit a82f289 into googleapis:master May 27, 2020
gcf-merge-on-green bot pushed a commit that referenced this pull request Jun 2, 2020
Children PR of #26.

This PR includes AsyncIO version of:
* Polling future
* Page iterator

The AsyncIO version of polling future still uses the same mechanism as the sync version. The AsyncIO polling future tries to update its own state whenever the application want to access information or perform actions.

For page iterator, it has similar interface design as sync version. But instead of fulfilling normal generator protocol, it is based on the async generator.

Related #23
gcf-merge-on-green bot pushed a commit that referenced this pull request Jun 4, 2020
@busunkim96 busunkim96 mentioned this pull request Jun 17, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants