8000 feat: Add OperationsRestAsyncTransport to support long running operat… · googleapis/python-api-core@0ee82e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ee82e0

Browse files
committed
feat: Add OperationsRestAsyncTransport to support long running operations
1 parent 3f26e81 commit 0ee82e0

File tree

5 files changed

+575
-14
lines changed

5 files changed

+575
-14
lines changed

google/api_core/operations_v1/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,21 @@
2121
from google.api_core.operations_v1.operations_client import OperationsClient
2222
from google.api_core.operations_v1.transports.rest import OperationsRestTransport
2323

24+
try:
25+
from google.api_core.operations_v1.transports.rest_asyncio import (
26+
OperationsRestAsyncTransport,
27+
)
28+
29+
HAS_ASYNC_TRANSPORT = True
30+
except ImportError:
31+
# Don't raise an exception if `OperationsRestAsyncTransport` cannot be imported
32+
# so that OperationsRestTransport can still be imported
33+
HAS_ASYNC_TRANSPORT = False
34+
2435
__all__ = [
2536
"AbstractOperationsClient",
2637
"OperationsAsyncClient",
2738
"OperationsClient",
2839
"OperationsRestTransport",
40+
"OperationsRestAsyncTransport",
2941
]

google/api_core/operations_v1/transports/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@
1818
from .base import OperationsTransport
1919
from .rest import OperationsRestTransport
2020

21+
try:
22+
from .rest_asyncio import OperationsRestAsyncTransport
23+
24+
HAS_ASYNC_TRANSPORT = True
25+
except ImportError:
26+
# Don't raise an exception if `OperationsRestAsyncTransport` cannot be imported
27+
# so that OperationsRestTransport can still be imported
28+
HAS_ASYNC_TRANSPORT = False
2129

2230
# Compile a registry of transports.
2331
_transport_registry = OrderedDict()
2432
_transport_registry["rest"] = OperationsRestTransport
2533

34+
if HAS_ASYNC_TRANSPORT:
35+
_transport_registry["rest_asyncio"] = OperationsRestAsyncTransport
36+
2637
__all__ = (
2738
"OperationsTransport",
2839
"OperationsRestTransport",
40+
"OperationsRestAsyncTransport",
2941
)

google/api_core/operations_v1/transports/base.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from google.api_core import exceptions as core_exceptions # type: ignore
2121
from google.api_core import gapic_v1 # type: ignore
2222
from google.api_core import retry as retries # type: ignore
23+
from google.api_core import retry_async as retries_async # type: ignore
2324
from google.api_core import version
2425
import google.auth # type: ignore
2526
from google.auth import credentials as ga_credentials # type: ignore
@@ -115,12 +116,13 @@ def __init__(
115116
# Save the credentials.
116117
self._credentials = credentials
117118

118-
def _prep_wrapped_messages(self, client_info):
119+
def _prep_wrapped_messages(self, client_info, is_async=False):
119120
# Precompute the wrapped methods.
121+
retry_class = retries_async.AsyncRetry if is_async else retries.Retry
120122
self._wrapped_methods = {
121123
self.list_operations: gapic_v1.method.wrap_method(
122124
self.list_operations,
123-
default_retry=retries.Retry(
125+
default_retry=retry_class(
124126
initial=0.5,
125127
maximum=10.0,
126128
multiplier=2.0,
@@ -135,7 +137,7 @@ def _prep_wrapped_messages(self, client_info):
135137
),
136138
self.get_operation: gapic_v1.method.wrap_method(
137139
self.get_operation,
138-
default_retry=retries.Retry(
140+
default_retry=retry_class(
139141
initial=0.5,
140142
maximum=10.0,
141143
multiplier=2.0,
@@ -150,7 +152,7 @@ def _prep_wrapped_messages(self, client_info):
150152
),
151153
self.delete_operation: gapic_v1.method.wrap_method(
152154
self.delete_operation,
153-
default_retry=retries.Retry(
155+
default_retry=retry_class(
154156
initial=0.5,
155157
maximum=10.0,
156158
multiplier=2.0,
@@ -165,7 +167,7 @@ def _prep_wrapped_messages(self, client_info):
165167
),
166168
self.cancel_operation: gapic_v1.method.wrap_method(
167169
self.cancel_operation,
168-
default_retry=retries.Retry(
170+
default_retry=retry_class(
169171
initial=0.5,
170172
maximum=10.0,
171173
multiplier=2.0,

0 commit comments

Comments
 (0)
0