Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AsyncIO Integration [Part 1]#26

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
busunkim96 merged 1 commit intogoogleapis:masterfromlidizheng:aio-part-1
May 27, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionsdocs/retry.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,10 @@ Retry
.. automodule:: google.api_core.retry
:members:
:show-inheritance:

Retry in AsyncIO
----------------

.. automodule:: google.api_core.retry_async
:members:
:show-inheritance:
8 changes: 7 additions & 1 deletiongoogle/api_core/exceptions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -444,6 +444,10 @@ def from_grpc_status(status_code, message, **kwargs):
return error


def _is_informative_grpc_error(rpc_exc):
return hasattr(rpc_exc, "code") and hasattr(rpc_exc, "details")


def from_grpc_error(rpc_exc):
"""Create a :class:`GoogleAPICallError` from a :class:`grpc.RpcError`.

Expand All@@ -454,7 +458,9 @@ def from_grpc_error(rpc_exc):
GoogleAPICallError: An instance of the appropriate subclass of
:class:`GoogleAPICallError`.
"""
if isinstance(rpc_exc, grpc.Call):
# NOTE(lidiz) All gRPC error shares the parent class grpc.RpcError.
# However, check for grpc.RpcError breaks backward compatibility.
if isinstance(rpc_exc, grpc.Call) or _is_informative_grpc_error(rpc_exc):
return from_grpc_status(
rpc_exc.code(), rpc_exc.details(), errors=(rpc_exc,), response=rpc_exc
)
Expand Down
6 changes: 6 additions & 0 deletionsgoogle/api_core/gapic_v1/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,9 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

from google.api_core.gapic_v1 import client_info
from google.api_core.gapic_v1 import config
from google.api_core.gapic_v1 import method
from google.api_core.gapic_v1 import routing_header

__all__ = ["client_info", "config", "method", "routing_header"]

if sys.version_info >= (3, 6):
from google.api_core.gapic_v1 import config_async # noqa: F401
__all__.append("config_async")
10 changes: 6 additions & 4 deletionsgoogle/api_core/gapic_v1/config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def _exception_class_for_grpc_status_name(name):
returnexceptions.exception_class_for_grpc_status(getattr(grpc.StatusCode,name))


def_retry_from_retry_config(retry_params,retry_codes):
def_retry_from_retry_config(retry_params,retry_codes,retry_impl=retry.Retry):
"""Creates a Retry object given a gapic retry configuration.
Args:
Expand All@@ -70,7 +70,7 @@ def _retry_from_retry_config(retry_params, retry_codes):
exception_classes= [
_exception_class_for_grpc_status_name(code)forcodeinretry_codes
]
returnretry.Retry(
returnretry_impl(
retry.if_exception_type(*exception_classes),
initial=(retry_params["initial_retry_delay_millis"]/_MILLIS_PER_SECOND),
maximum=(retry_params["max_retry_delay_millis"]/_MILLIS_PER_SECOND),
Expand DownExpand Up@@ -110,7 +110,7 @@ def _timeout_from_retry_config(retry_params):
MethodConfig=collections.namedtuple("MethodConfig", ["retry","timeout"])


defparse_method_configs(interface_config):
defparse_method_configs(interface_config,retry_impl=retry.Retry):
"""Creates default retry and timeout objects for each method in a gapic
interface config.
Expand All@@ -120,6 +120,8 @@ def parse_method_configs(interface_config):
an interface named ``google.example.v1.ExampleService`` you would
pass in just that interface's configuration, for example
``gapic_config['interfaces']['google.example.v1.ExampleService']``.
retry_impl (Callable): The constructor that creates a retry decorator
that will be applied to the method based on method configs.
Returns:
Mapping[str, MethodConfig]: A mapping of RPC method names to their
Expand DownExpand Up@@ -151,7 +153,7 @@ def parse_method_configs(interface_config):
ifretry_params_nameisnotNone:
retry_params=retry_params_map[retry_params_name]
retry_=_retry_from_retry_config(
retry_params,retry_codes_map[method_params["retry_codes_name"]]
retry_params,retry_codes_map[method_params["retry_codes_name"]],retry_impl
)
timeout_=_timeout_from_retry_config(retry_params)

Expand Down
42 changes: 42 additions & 0 deletionsgoogle/api_core/gapic_v1/config_async.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""AsyncIO helpers for loading gapic configuration data.

The Google API generator creates supplementary configuration for each RPC
method to tell the client library how to deal with retries and timeouts.
"""

from google.api_core import retry_async
from google.api_core.gapic_v1 import config
from google.api_core.gapic_v1.config import MethodConfig # noqa: F401


def parse_method_configs(interface_config):
"""Creates default retry and timeout objects for each method in a gapic
interface config with AsyncIO semantics.

Args:
interface_config (Mapping): The interface config section of the full
gapic library config. For example, If the full configuration has
an interface named ``google.example.v1.ExampleService`` you would
pass in just that interface's configuration, for example
``gapic_config['interfaces']['google.example.v1.ExampleService']``.

Returns:
Mapping[str, MethodConfig]: A mapping of RPC method names to their
configuration.
"""
return config.parse_method_configs(
interface_config,
retry_impl=retry_async.AsyncRetry)
Loading

[8]ページ先頭

©2009-2025 Movatter.jp