Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 07a30a1

Browse files
fix: use correct retry deadline (#134)
* changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * chore: upgrade gapic-generator-python to 0.43.1 PiperOrigin-RevId: 364411656 Source-Author: Google APIs <[email protected]> Source-Date: Mon Mar 22 14:40:22 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 149a3a84c29c9b8189576c7442ccb6dcf6a8f95b Source-Link: googleapis/googleapis@149a3a8
1 parent c211b69 commit 07a30a1

File tree

12 files changed

+276
-430
lines changed

12 files changed

+276
-430
lines changed

google/cloud/speech_v1/services/speech/async_client.py

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ async def recognize(
244244
predicate=retries.if_exception_type(
245245
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
246246
),
247+
deadline=5000.0,
247248
),
248249
default_timeout=5000.0,
249250
client_info=DEFAULT_CLIENT_INFO,
@@ -455,6 +456,7 @@ def streaming_recognize(
455456
predicate=retries.if_exception_type(
456457
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
457458
),
459+
deadline=5000.0,
458460
),
459461
default_timeout=5000.0,
460462
client_info=DEFAULT_CLIENT_INFO,

google/cloud/speech_v1/services/speech/transports/base.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,20 @@ def __init__(
6969
scope (Optional[Sequence[str]]): A list of scopes.
7070
quota_project_id (Optional[str]): An optional project to use for billing
7171
and quota.
72-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
73-
The client info used to send a user-agent string along with
74-
API requests. If ``None``, then default info will be used.
75-
Generally, you only need to set this if you're developing
72+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
73+
The client info used to send a user-agent string along with
74+
API requests. If ``None``, then default info will be used.
75+
Generally, you only need to set this if you're developing
7676
your own client library.
7777
"""
7878
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
7979
if ":" not in host:
8080
host += ":443"
8181
self._host = host
8282

83+
# Save the scopes.
84+
self._scopes = scopes or self.AUTH_SCOPES
85+
8386
# If no credentials are provided, then determine the appropriate
8487
# defaults.
8588
if credentials and credentials_file:
@@ -89,20 +92,17 @@ def __init__(
8992

9093
if credentials_file is not None:
9194
credentials, _ = auth.load_credentials_from_file(
92-
credentials_file, scopes=scopes, quota_project_id=quota_project_id
95+
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
9396
)
9497

9598
elif credentials is None:
9699
credentials, _ = auth.default(
97-
scopes=scopes, quota_project_id=quota_project_id
100+
scopes=self._scopes, quota_project_id=quota_project_id
98101
)
99102

100103
# Save the credentials.
101104
self._credentials = credentials
102105

103-
# Lifted into its own function so it can be stubbed out during tests.
104-
self._prep_wrapped_messages(client_info)
105-
106106
def _prep_wrapped_messages(self, client_info):
107107
# Precompute the wrapped methods.
108108
self._wrapped_methods = {
@@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info):
115115
predicate=retries.if_exception_type(
116116
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
117117
),
118+
deadline=5000.0,
118119
),
119120
default_timeout=5000.0,
120121
client_info=client_info,
@@ -133,6 +134,7 @@ def _prep_wrapped_messages(self, client_info):
133134
predicate=retries.if_exception_type(
134135
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
135136
),
137+
deadline=5000.0,
136138
),
137139
default_timeout=5000.0,
138140
client_info=client_info,

google/cloud/speech_v1/services/speech/transports/grpc.py

+38-65
Original file line numberDiff line numberDiff line change
@@ -108,97 +108,70 @@ def __init__(
108108
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
109109
and ``credentials_file`` are passed.
110110
"""
111+
self._grpc_channel = None
111112
self._ssl_channel_credentials = ssl_channel_credentials
113+
self._stubs: Dict[str, Callable] = {}
114+
self._operations_client = None
112115

113116
if api_mtls_endpoint:
114117
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
115118
if client_cert_source:
116119
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
117120

118121
if channel:
119-
# Sanity check: Ensure that channel and credentials are not both
120-
# provided.
122+
# Ignore credentials if a channel was passed.
121123
credentials = False
122-
123124
# If a channel was explicitly provided, set it.
124125
self._grpc_channel = channel
125126
self._ssl_channel_credentials = None
126-
elif api_mtls_endpoint:
127-
host = (
128-
api_mtls_endpoint
129-
if ":" in api_mtls_endpoint
130-
else api_mtls_endpoint + ":443"
131-
)
132-
133-
if credentials is None:
134-
credentials, _ = auth.default(
135-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
136-
)
137-
138-
# Create SSL credentials with client_cert_source or application
139-
# default SSL credentials.
140-
if client_cert_source:
141-
cert, key = client_cert_source()
142-
ssl_credentials = grpc.ssl_channel_credentials(
143-
certificate_chain=cert, private_key=key
144-
)
145-
else:
146-
ssl_credentials = SslCredentials().ssl_credentials
147127

148-
# create a new channel. The provided one is ignored.
149-
self._grpc_channel = type(self).create_channel(
150-
host,
151-
credentials=credentials,
152-
credentials_file=credentials_file,
153-
ssl_credentials=ssl_credentials,
154-
scopes=scopes or self.AUTH_SCOPES,
155-
quota_project_id=quota_project_id,
156-
options=[
157-
("grpc.max_send_message_length", -1),
158-
("grpc.max_receive_message_length", -1),
159-
],
160-
)
161-
self._ssl_channel_credentials = ssl_credentials
162128
else:
163-
host = host if ":" in host else host + ":443"
129+
if api_mtls_endpoint:
130+
host = api_mtls_endpoint
131+
132+
# Create SSL credentials with client_cert_source or application
133+
# default SSL credentials.
134+
if client_cert_source:
135+
cert, key = client_cert_source()
136+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
137+
certificate_chain=cert, private_key=key
138+
)
139+
else:
140+
self._ssl_channel_credentials = SslCredentials().ssl_credentials
164141

165-
if credentials is None:
166-
credentials, _ = auth.default(
167-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
168-
)
142+
else:
143+
if client_cert_source_for_mtls and not ssl_channel_credentials:
144+
cert, key = client_cert_source_for_mtls()
145+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
146+
certificate_chain=cert, private_key=key
147+
)
169148

170-
if client_cert_source_for_mtls and not ssl_channel_credentials:
171-
cert, key = client_cert_source_for_mtls()
172-
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
173-
certificate_chain=cert, private_key=key
174-
)
149+
# The base transport sets the host, credentials and scopes
150+
super().__init__(
151+
host=host,
152+
credentials=credentials,
153+
credentials_file=credentials_file,
154+
scopes=scopes,
155+
quota_project_id=quota_project_id,
156+
client_info=client_info,
157+
)
175158

176-
# create a new channel. The provided one is ignored.
159+
if not self._grpc_channel:
177160
self._grpc_channel = type(self).create_channel(
178-
host,
179-
credentials=credentials,
161+
self._host,
162+
credentials=self._credentials,
180163
credentials_file=credentials_file,
164+
scopes=self._scopes,
181165
ssl_credentials=self._ssl_channel_credentials,
182-
scopes=scopes or self.AUTH_SCOPES,
183166
quota_project_id=quota_project_id,
184167
options=[
185168
("grpc.max_send_message_length", -1),
186169
("grpc.max_receive_message_length", -1),
187170
],
188171
)
189172

190-
self._stubs = {} # type: Dict[str, Callable]
191-
self._operations_client = None
192-
193-
# Run the base constructor.
194-
super().__init__(
195-
host=host,
196-
credentials=credentials,
197-
credentials_file=credentials_file,
198-
scopes=scopes or self.AUTH_SCOPES,
199-
quota_project_id=quota_project_id,
200-
client_info=client_info,
201-
)
173+
# Wrap messages. This must be done after self._grpc_channel exists
174+
self._prep_wrapped_messages(client_info)
202175

203176
@classmethod
204177
def create_channel(
@@ -212,7 +185,7 @@ def create_channel(
212185
) -> grpc.Channel:
213186
"""Create and return a gRPC channel object.
214187
Args:
215-
address (Optional[str]): The host for the channel to use.
188+
host (Optional[str]): The host for the channel to use.
216189
credentials (Optional[~.Credentials]): The
217190
authorization credentials to attach to requests. These
218191
credentials identify this application to the service. If

google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py

+42-69
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def create_channel(
6363
) -> aio.Channel:
6464
"""Create and return a gRPC AsyncIO channel object.
6565
Args:
66-
address (Optional[str]): The host for the channel to use.
66+
host (Optional[str]): The host for the channel to use.
6767
credentials (Optional[~.Credentials]): The
6868
authorization credentials to attach to requests. These
6969
credentials identify this application to the service. If
@@ -141,10 +141,10 @@ def __init__(
141141
ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
142142
quota_project_id (Optional[str]): An optional project to use for billing
143143
and quota.
144-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
145-
The client info used to send a user-agent string along with
146-
API requests. If ``None``, then default info will be used.
147-
Generally, you only need to set this if you're developing
144+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
145+
The client info used to send a user-agent string along with
146+
API requests. If ``None``, then default info will be used.
147+
Generally, you only need to set this if you're developing
148148
your own client library.
149149
150150
Raises:
@@ -153,97 +153,70 @@ def __init__(
153153
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
154154
and ``credentials_file`` are passed.
155155
"""
156+
self._grpc_channel = None
156157
self._ssl_channel_credentials = ssl_channel_credentials
158+
self._stubs: Dict[str, Callable] = {}
159+
self._operations_client = None
157160

158161
if api_mtls_endpoint:
159162
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
160163
if client_cert_source:
161164
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
162165

163166
if channel:
164-
# Sanity check: Ensure that channel and credentials are not both
165-
# provided.
167+
# Ignore credentials if a channel was passed.
166168
credentials = False
167-
168169
# If a channel was explicitly provided, set it.
169170
self._grpc_channel = channel
170171
self._ssl_channel_credentials = None
171-
elif api_mtls_endpoint:
172-
host = (
173-
api_mtls_endpoint
174-
if ":" in api_mtls_endpoint
175-
else api_mtls_endpoint + ":443"
176-
)
177-
178-
if credentials is None:
179-
credentials, _ = auth.default(
180-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
181-
)
182-
183-
# Create SSL credentials with client_cert_source or application
184-
# default SSL credentials.
185-
if client_cert_source:
186-
cert, key = client_cert_source()
187-
ssl_credentials = grpc.ssl_channel_credentials(
188-
certificate_chain=cert, private_key=key
189-
)
190-
else:
191-
ssl_credentials = SslCredentials().ssl_credentials
192172

193-
# create a new channel. The provided one is ignored.
194-
self._grpc_channel = type(self).create_channel(
195-
host,
196-
credentials=credentials,
197-
credentials_file=credentials_file,
198-
ssl_credentials=ssl_credentials,
199-
scopes=scopes or self.AUTH_SCOPES,
200-
quota_project_id=quota_project_id,
201-
options=[
202-
("grpc.max_send_message_length", -1),
203-
("grpc.max_receive_message_length", -1),
204-
],
205-
)
206-
self._ssl_channel_credentials = ssl_credentials
207173
else:
208-
host = host if ":" in host else host + ":443"
174+
if api_mtls_endpoint:
175+
host = api_mtls_endpoint
176+
177+
# Create SSL credentials with client_cert_source or application
178+
# default SSL credentials.
179+
if client_cert_source:
180+
cert, key = client_cert_source()
181+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
182+
certificate_chain=cert, private_key=key
183+
)
184+
else:
185+
self._ssl_channel_credentials = SslCredentials().ssl_credentials
209186

210-
if credentials is None:
211-
credentials, _ = auth.default(
212-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
213-
)
187+
else:
188+
if client_cert_source_for_mtls and not ssl_channel_credentials:
189+
cert, key = client_cert_source_for_mtls()
190+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
191+
certificate_chain=cert, private_key=key
192+
)
214193

215-
if client_cert_source_for_mtls and not ssl_channel_credentials:
216-
cert, key = client_cert_source_for_mtls()
217-
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
218-
certificate_chain=cert, private_key=key
219-
)
194+
# The base transport sets the host, credentials and scopes
195+
super().__init__(
196+
host=host,
197+
credentials=credentials,
198+
credentials_file=credentials_file,
199+
scopes=scopes,
200+
quota_project_id=quota_project_id,
201+
client_info=client_info,
202+
)
220203

221-
# create a new channel. The provided one is ignored.
204+
if not self._grpc_channel:
222205
self._grpc_channel = type(self).create_channel(
223-
host,
224-
credentials=credentials,
206+
self._host,
207+
credentials=self._credentials,
225208
credentials_file=credentials_file,
209+
scopes=self._scopes,
226210
ssl_credentials=self._ssl_channel_credentials,
227-
scopes=scopes or self.AUTH_SCOPES,
228211
quota_project_id=quota_project_id,
229212
options=[
230213
("grpc.max_send_message_length", -1),
231214
("grpc.max_receive_message_length", -1),
232215
],
233216
)
234217

235-
# Run the base constructor.
236-
super().__init__(
237-
host=host,
238-
credentials=credentials,
239-
credentials_file=credentials_file,
240-
scopes=scopes or self.AUTH_SCOPES,
241-
quota_project_id=quota_project_id,
242-
client_info=client_info,
243-
)
244-
245-
self._stubs = {}
246-
self._operations_client = None
218+
# Wrap messages. This must be done after self._grpc_channel exists
219+
self._prep_wrapped_messages(client_info)
247220

248221
@property
249222
def grpc_channel(self) -> aio.Channel:

0 commit comments

Comments
 (0)