Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 090c723

Browse files
feat: add context manager support in client (#102)
- [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: googleapis/googleapis@787f8c9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
1 parent ab3f325 commit 090c723

File tree

28 files changed

+347
-16
lines changed

28 files changed

+347
-16
lines changed

google/cloud/workflows/executions_v1/services/executions/async_client.py

+6
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ async def cancel_execution(
479479
# Done; return the response.
480480
return response
481481

482+
async def __aenter__(self):
483+
return self
484+
485+
async def __aexit__(self, exc_type, exc, tb):
486+
await self.transport.close()
487+
482488

483489
try:
484490
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/workflows/executions_v1/services/executions/client.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,7 @@ def __init__(
363363
client_cert_source_for_mtls=client_cert_source_func,
364364
quota_project_id=client_options.quota_project_id,
365365
client_info=client_info,
366-
always_use_jwt_access=(
367-
Transport == type(self).get_transport_class("grpc")
368-
or Transport == type(self).get_transport_class("grpc_asyncio")
369-
),
366+
always_use_jwt_access=True,
370367
)
371368

372369
def list_executions(
@@ -688,6 +685,19 @@ def cancel_execution(
688685
# Done; return the response.
689686
return response
690687

688+
def __enter__(self):
689+
return self
690+
691+
def __exit__(self, type, value, traceback):
692+
"""Releases underlying transport's resources.
693+
694+
.. warning::
695+
ONLY use as a context manager if the transport is NOT shared
696+
with other clients! Exiting the with block will CLOSE the transport
697+
and may cause errors in other clients!
698+
"""
699+
self.transport.close()
700+
691701

692702
try:
693703
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/workflows/executions_v1/services/executions/transports/base.py

+9
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ def _prep_wrapped_messages(self, client_info):
166166
),
167167
}
168168

169+
def close(self):
170+
"""Closes resources associated with the transport.
171+
172+
.. warning::
173+
Only call this method if the transport is NOT shared
174+
with other clients - this may cause errors in other clients!
175+
"""
176+
raise NotImplementedError()
177+
169178
@property
170179
def list_executions(
171180
self,

google/cloud/workflows/executions_v1/services/executions/transports/grpc.py

+3
Original file line numberDiff line numberDiff line change
@@ -337,5 +337,8 @@ def cancel_execution(
337337
)
338338
return self._stubs["cancel_execution"]
339339

340+
def close(self):
341+
self.grpc_channel.close()
342+
340343

341344
__all__ = ("ExecutionsGrpcTransport",)

google/cloud/workflows/executions_v1/services/executions/transports/grpc_asyncio.py

+3
Original file line numberDiff line numberDiff line change
@@ -340,5 +340,8 @@ def cancel_execution(
340340
)
341341
return self._stubs["cancel_execution"]
342342

343+
def close(self):
344+
return self.grpc_channel.close()
345+
343346

344347
__all__ = ("ExecutionsGrpcAsyncIOTransport",)

google/cloud/workflows/executions_v1/types/executions.py

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class State(proto.Enum):
8484

8585
class Error(proto.Message):
8686
r"""Error describes why the execution was abnormally terminated.
87+
8788
Attributes:
8889
payload (str):
8990
Error payload returned by the execution,
@@ -108,6 +109,7 @@ class Error(proto.Message):
108109

109110
class ListExecutionsRequest(proto.Message):
110111
r"""Request for the [ListExecutions][] method.
112+
111113
Attributes:
112114
parent (str):
113115
Required. Name of the workflow for which the

google/cloud/workflows/executions_v1beta/services/executions/async_client.py

+6
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ async def cancel_execution(
480480
# Done; return the response.
481481
return response
482482

483+
async def __aenter__(self):
484+
return self
485+
486+
async def __aexit__(self, exc_type, exc, tb):
487+
await self.transport.close()
488+
483489

484490
try:
485491
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/workflows/executions_v1beta/services/executions/client.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,7 @@ def __init__(
364364
client_cert_source_for_mtls=client_cert_source_func,
365365
quota_project_id=client_options.quota_project_id,
366366
client_info=client_info,
367-
always_use_jwt_access=(
368-
Transport == type(self).get_transport_class("grpc")
369-
or Transport == type(self).get_transport_class("grpc_asyncio")
370-
),
367+
always_use_jwt_access=True,
371368
)
372369

373370
def list_executions(
@@ -689,6 +686,19 @@ def cancel_execution(
689686
# Done; return the response.
690687
return response
691688

689+
def __enter__(self):
690+
return self
691+
692+
def __exit__(self, type, value, traceback):
693+
"""Releases underlying transport's resources.
694+
695+
.. warning::
696+
ONLY use as a context manager if the transport is NOT shared
697+
with other clients! Exiting the with block will CLOSE the transport
698+
and may cause errors in other clients!
699+
"""
700+
self.transport.close()
701+
692702

693703
try:
694704
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/workflows/executions_v1beta/services/executions/transports/base.py

+9
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ def _prep_wrapped_messages(self, client_info):
166166
),
167167
}
168168

169+
def close(self):
170+
"""Closes resources associated with the transport.
171+
172+
.. warning::
173+
Only call this method if the transport is NOT shared
174+
with other clients - this may cause errors in other clients!
175+
"""
176+
raise NotImplementedError()
177+
169178
@property
170179
def list_executions(
171180
self,

google/cloud/workflows/executions_v1beta/services/executions/transports/grpc.py

+3
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,8 @@ def cancel_execution(
338338
)
339339
return self._stubs["cancel_execution"]
340340

341+
def close(self):
342+
self.grpc_channel.close()
343+
341344

342345
__all__ = ("ExecutionsGrpcTransport",)

google/cloud/workflows/executions_v1beta/services/executions/transports/grpc_asyncio.py

+3
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,8 @@ def cancel_execution(
341341
)
342342
return self._stubs["cancel_execution"]
343343

344+
def close(self):
345+
return self.grpc_channel.close()
346+
344347

345348
__all__ = ("ExecutionsGrpcAsyncIOTransport",)

google/cloud/workflows/executions_v1beta/types/executions.py

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class State(proto.Enum):
8484

8585
class Error(proto.Message):
8686
r"""Error describes why the execution was abnormally terminated.
87+
8788
Attributes:
8889
payload (str):
8990
Error payload returned by the execution,

google/cloud/workflows_v1/services/workflows/async_client.py

+6
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,12 @@ async def update_workflow(
630630
# Done; return the response.
631631
return response
632632

633+
async def __aenter__(self):
634+
return self
635+
636+
async def __aexit__(self, exc_type, exc, tb):
637+
await self.transport.close()
638+
633639

634640
try:
635641
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/workflows_v1/services/workflows/client.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,7 @@ def __init__(
350350
client_cert_source_for_mtls=client_cert_source_func,
351351
quota_project_id=client_options.quota_project_id,
352352
client_info=client_info,
353-
always_use_jwt_access=(
354-
Transport == type(self).get_transport_class("grpc")
355-
or Transport == type(self).get_transport_class("grpc_asyncio")
356-
),
353+
always_use_jwt_access=True,
357354
)
358355

359356
def list_workflows(
@@ -823,6 +820,19 @@ def update_workflow(
823820
# Done; return the response.
824821
return response
825822

823+
def __enter__(self):
824+
return self
825+
826+
def __exit__(self, type, value, traceback):
827+
"""Releases underlying transport's resources.
828+
829+
.. warning::
830+
ONLY use as a context manager if the transport is NOT shared
831+
with other clients! Exiting the with block will CLOSE the transport
832+
and may cause errors in other clients!
833+
"""
834+
self.transport.close()
835+
826836

827837
try:
828838
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/workflows_v1/services/workflows/transports/base.py

+9
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ def _prep_wrapped_messages(self, client_info):
171171
),
172172
}
173173

174+
def close(self):
175+
"""Closes resources associated with the transport.
176+
177+
.. warning::
178+
Only call this method if the transport is NOT shared
179+
with other clients - this may cause errors in other clients!
180+
"""
181+
raise NotImplementedError()
182+
174183
@property
175184
def operations_client(self) -> operations_v1.OperationsClient:
176185
"""Return the client designed to process long-running operations."""

google/cloud/workflows_v1/services/workflows/transports/grpc.py

+3
Original file line numberDiff line numberDiff line change
@@ -385,5 +385,8 @@ def update_workflow(
385385
)
386386
return self._stubs["update_workflow"]
387387

388+
def close(self):
389+
self.grpc_channel.close()
390+
388391

389392
__all__ = ("WorkflowsGrpcTransport",)

google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py

+3
Original file line numberDiff line numberDiff line change
@@ -398,5 +398,8 @@ def update_workflow(
398398
)
399399
return self._stubs["update_workflow"]
400400

401+
def close(self):
402+
return self.grpc_channel.close()
403+
401404

402405
__all__ = ("WorkflowsGrpcAsyncIOTransport",)

google/cloud/workflows_v1/types/workflows.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
class Workflow(proto.Message):
3838
r"""Workflow program to be executed by Workflows.
39+
3940
Attributes:
4041
name (str):
4142
The resource name of the workflow.
@@ -265,6 +266,7 @@ class UpdateWorkflowRequest(proto.Message):
265266

266267
class OperationMetadata(proto.Message):
267268
r"""Represents the metadata of the long-running operation.
269+
268270
Attributes:
269271
create_time (google.protobuf.timestamp_pb2.Timestamp):
270272
The time the operation was created.

google/cloud/workflows_v1beta/services/workflows/async_client.py

+6
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,12 @@ async def update_workflow(
630630
# Done; return the response.
631631
return response
632632

633+
async def __aenter__(self):
634+
return self
635+
636+
async def __aexit__(self, exc_type, exc, tb):
637+
await self.transport.close()
638+
633639

634640
try:
635641
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/workflows_v1beta/services/workflows/client.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,7 @@ def __init__(
350350
client_cert_source_for_mtls=client_cert_source_func,
351351
quota_project_id=client_options.quota_project_id,
352352
client_info=client_info,
353-
always_use_jwt_access=(
354-
Transport == type(self).get_transport_class("grpc")
355-
or Transport == type(self).get_transport_class("grpc_asyncio")
356-
),
353+
always_use_jwt_access=True,
357354
)
358355

359356
def list_workflows(
@@ -823,6 +820,19 @@ def update_workflow(
823820
# Done; return the response.
824821
return response
825822

823+
def __enter__(self):
824+
return self
825+
826+
def __exit__(self, type, value, traceback):
827+
"""Releases underlying transport's resources.
828+
829+
.. warning::
830+
ONLY use as a context manager if the transport is NOT shared
831+
with other clients! Exiting the with block will CLOSE the transport
832+
and may cause errors in other clients!
833+
"""
834+
self.transport.close()
835+
826836

827837
try:
828838
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/workflows_v1beta/services/workflows/transports/base.py

+9
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ def _prep_wrapped_messages(self, client_info):
171171
),
172172
}
173173

174+
def close(self):
175+
"""Closes resources associated with the transport.
176+
177+
.. warning::
178+
Only call this method if the transport is NOT shared
179+
with other clients - this may cause errors in other clients!
180+
"""
181+
raise NotImplementedError()
182+
174183
@property
175184
def operations_client(self) -> operations_v1.OperationsClient:
176185
"""Return the client designed to process long-running operations."""

google/cloud/workflows_v1beta/services/workflows/transports/grpc.py

+3
Original file line numberDiff line numberDiff line change
@@ -385,5 +385,8 @@ def update_workflow(
385385
)
386386
return self._stubs["update_workflow"]
387387

388+
def close(self):
389+
self.grpc_channel.close()
390+
388391

389392
__all__ = ("WorkflowsGrpcTransport",)

google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py

+3
Original file line numberDiff line numberDiff line change
@@ -398,5 +398,8 @@ def update_workflow(
398398
)
399399
return self._stubs["update_workflow"]
400400

401+
def close(self):
402+
return self.grpc_channel.close()
403+
401404

402405
__all__ = ("WorkflowsGrpcAsyncIOTransport",)

google/cloud/workflows_v1beta/types/workflows.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
class Workflow(proto.Message):
3838
r"""Workflow program to be executed by Workflows.
39+
3940
Attributes:
4041
name (str):
4142
The resource name of the workflow.
@@ -265,6 +266,7 @@ class UpdateWorkflowRequest(proto.Message):
265266

266267
class OperationMetadata(proto.Message):
267268
r"""Represents the metadata of the long-running operation.
269+
268270
Attributes:
269271
create_time (google.protobuf.timestamp_pb2.Timestamp):
270272
The time the operation was created.

0 commit comments

Comments
 (0)