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

Appearance settings

Commit 21bdadd

Browse filesBrowse files
committed
feat: Add OperationsRestAsyncTransport to support long running operations
1 parent 58516ef commit 21bdadd
Copy full SHA for 21bdadd

File tree

Expand file treeCollapse file tree

6 files changed

+580
-17
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+580
-17
lines changed

‎google/api_core/operations_v1/__init__.py

Copy file name to clipboardExpand all lines: google/api_core/operations_v1/__init__.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,23 @@
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 as e:
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",
2940
]
41+
42+
if HAS_ASYNC_TRANSPORT:
43+
__all__.append("OperationsRestAsyncTransport")

‎google/api_core/operations_v1/transports/__init__.py

Copy file name to clipboardExpand all lines: google/api_core/operations_v1/transports/__init__.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,26 @@
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 as e:
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",
2940
)
41+
42+
if HAS_ASYNC_TRANSPORT:
43+
__all__.append("OperationsRestAsyncTransport")

‎google/api_core/operations_v1/transports/base.py

Copy file name to clipboardExpand all lines: google/api_core/operations_v1/transports/base.py
+7-5Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.