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

Commit

Permalink
feat: add context manager support in client (#102)
Browse files Browse the repository at this point in the history
- [ ] 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: googleapis/googleapis-gen@81decff
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
  • Loading branch information
gcf-owl-bot[bot] committed Oct 7, 2021
1 parent ab3f325 commit 090c723
Show file tree
Hide file tree
Showing 28 changed files with 347 additions and 16 deletions.
Expand Up @@ -479,6 +479,12 @@ async def cancel_execution(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/workflows/executions_v1/services/executions/client.py
Expand Up @@ -363,10 +363,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_executions(
Expand Down Expand Up @@ -688,6 +685,19 @@ def cancel_execution(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -166,6 +166,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def list_executions(
self,
Expand Down
Expand Up @@ -337,5 +337,8 @@ def cancel_execution(
)
return self._stubs["cancel_execution"]

def close(self):
self.grpc_channel.close()


__all__ = ("ExecutionsGrpcTransport",)
Expand Up @@ -340,5 +340,8 @@ def cancel_execution(
)
return self._stubs["cancel_execution"]

def close(self):
return self.grpc_channel.close()


__all__ = ("ExecutionsGrpcAsyncIOTransport",)
2 changes: 2 additions & 0 deletions google/cloud/workflows/executions_v1/types/executions.py
Expand Up @@ -84,6 +84,7 @@ class State(proto.Enum):

class Error(proto.Message):
r"""Error describes why the execution was abnormally terminated.
Attributes:
payload (str):
Error payload returned by the execution,
Expand All @@ -108,6 +109,7 @@ class Error(proto.Message):

class ListExecutionsRequest(proto.Message):
r"""Request for the [ListExecutions][] method.
Attributes:
parent (str):
Required. Name of the workflow for which the
Expand Down
Expand Up @@ -480,6 +480,12 @@ async def cancel_execution(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -364,10 +364,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_executions(
Expand Down Expand Up @@ -689,6 +686,19 @@ def cancel_execution(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -166,6 +166,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def list_executions(
self,
Expand Down
Expand Up @@ -338,5 +338,8 @@ def cancel_execution(
)
return self._stubs["cancel_execution"]

def close(self):
self.grpc_channel.close()


__all__ = ("ExecutionsGrpcTransport",)
Expand Up @@ -341,5 +341,8 @@ def cancel_execution(
)
return self._stubs["cancel_execution"]

def close(self):
return self.grpc_channel.close()


__all__ = ("ExecutionsGrpcAsyncIOTransport",)
Expand Up @@ -84,6 +84,7 @@ class State(proto.Enum):

class Error(proto.Message):
r"""Error describes why the execution was abnormally terminated.
Attributes:
payload (str):
Error payload returned by the execution,
Expand Down
6 changes: 6 additions & 0 deletions google/cloud/workflows_v1/services/workflows/async_client.py
Expand Up @@ -630,6 +630,12 @@ async def update_workflow(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/workflows_v1/services/workflows/client.py
Expand Up @@ -350,10 +350,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_workflows(
Expand Down Expand Up @@ -823,6 +820,19 @@ def update_workflow(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -171,6 +171,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
Expand Down
Expand Up @@ -385,5 +385,8 @@ def update_workflow(
)
return self._stubs["update_workflow"]

def close(self):
self.grpc_channel.close()


__all__ = ("WorkflowsGrpcTransport",)
Expand Up @@ -398,5 +398,8 @@ def update_workflow(
)
return self._stubs["update_workflow"]

def close(self):
return self.grpc_channel.close()


__all__ = ("WorkflowsGrpcAsyncIOTransport",)
2 changes: 2 additions & 0 deletions google/cloud/workflows_v1/types/workflows.py
Expand Up @@ -36,6 +36,7 @@

class Workflow(proto.Message):
r"""Workflow program to be executed by Workflows.
Attributes:
name (str):
The resource name of the workflow.
Expand Down Expand Up @@ -265,6 +266,7 @@ class UpdateWorkflowRequest(proto.Message):

class OperationMetadata(proto.Message):
r"""Represents the metadata of the long-running operation.
Attributes:
create_time (google.protobuf.timestamp_pb2.Timestamp):
The time the operation was created.
Expand Down
Expand Up @@ -630,6 +630,12 @@ async def update_workflow(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/workflows_v1beta/services/workflows/client.py
Expand Up @@ -350,10 +350,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_workflows(
Expand Down Expand Up @@ -823,6 +820,19 @@ def update_workflow(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -171,6 +171,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
Expand Down
Expand Up @@ -385,5 +385,8 @@ def update_workflow(
)
return self._stubs["update_workflow"]

def close(self):
self.grpc_channel.close()


__all__ = ("WorkflowsGrpcTransport",)
Expand Up @@ -398,5 +398,8 @@ def update_workflow(
)
return self._stubs["update_workflow"]

def close(self):
return self.grpc_channel.close()


__all__ = ("WorkflowsGrpcAsyncIOTransport",)
2 changes: 2 additions & 0 deletions google/cloud/workflows_v1beta/types/workflows.py
Expand Up @@ -36,6 +36,7 @@

class Workflow(proto.Message):
r"""Workflow program to be executed by Workflows.
Attributes:
name (str):
The resource name of the workflow.
Expand Down Expand Up @@ -265,6 +266,7 @@ class UpdateWorkflowRequest(proto.Message):

class OperationMetadata(proto.Message):
r"""Represents the metadata of the long-running operation.
Attributes:
create_time (google.protobuf.timestamp_pb2.Timestamp):
The time the operation was created.
Expand Down

0 comments on commit 090c723

Please sign in to comment.