Skip to content

Commit

Permalink
feat: add context manager support in client (#255)
Browse files Browse the repository at this point in the history
- [x] 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 9, 2021
1 parent e2f7b98 commit 9ad887f
Show file tree
Hide file tree
Showing 41 changed files with 564 additions and 29 deletions.
Expand Up @@ -1641,6 +1641,12 @@ async def list_reservation_topics(
# 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/pubsublite_v1/services/admin_service/client.py
Expand Up @@ -381,10 +381,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 create_topic(
Expand Down Expand Up @@ -1861,6 +1858,19 @@ def list_reservation_topics(
# 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 @@ -223,6 +223,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 @@ -767,5 +767,8 @@ def list_reservation_topics(
)
return self._stubs["list_reservation_topics"]

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


__all__ = ("AdminServiceGrpcTransport",)
Expand Up @@ -784,5 +784,8 @@ def list_reservation_topics(
)
return self._stubs["list_reservation_topics"]

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


__all__ = ("AdminServiceGrpcAsyncIOTransport",)
Expand Up @@ -370,6 +370,12 @@ async def list_partition_cursors(
# 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/pubsublite_v1/services/cursor_service/client.py
Expand Up @@ -346,10 +346,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 streaming_commit_cursor(
Expand Down Expand Up @@ -519,6 +516,19 @@ def list_partition_cursors(
# 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 @@ -197,6 +197,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 streaming_commit_cursor(
self,
Expand Down
Expand Up @@ -312,5 +312,8 @@ def list_partition_cursors(
)
return self._stubs["list_partition_cursors"]

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


__all__ = ("CursorServiceGrpcTransport",)
Expand Up @@ -317,5 +317,8 @@ def list_partition_cursors(
)
return self._stubs["list_partition_cursors"]

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


__all__ = ("CursorServiceGrpcAsyncIOTransport",)
Expand Up @@ -228,6 +228,12 @@ def assign_partitions(
# 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 @@ -331,10 +331,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 assign_partitions(
Expand Down Expand Up @@ -385,6 +382,19 @@ def assign_partitions(
# 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 @@ -159,6 +159,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 assign_partitions(
self,
Expand Down
Expand Up @@ -262,5 +262,8 @@ def assign_partitions(
)
return self._stubs["assign_partitions"]

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


__all__ = ("PartitionAssignmentServiceGrpcTransport",)
Expand Up @@ -268,5 +268,8 @@ def assign_partitions(
)
return self._stubs["assign_partitions"]

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


__all__ = ("PartitionAssignmentServiceGrpcAsyncIOTransport",)
Expand Up @@ -219,6 +219,12 @@ def publish(
# 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/pubsublite_v1/services/publisher_service/client.py
Expand Up @@ -332,10 +332,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 publish(
Expand Down Expand Up @@ -381,6 +378,19 @@ def publish(
# 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 @@ -159,6 +159,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 publish(
self,
Expand Down
Expand Up @@ -263,5 +263,8 @@ def publish(
)
return self._stubs["publish"]

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


__all__ = ("PublisherServiceGrpcTransport",)
Expand Up @@ -266,5 +266,8 @@ def publish(
)
return self._stubs["publish"]

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


__all__ = ("PublisherServiceGrpcAsyncIOTransport",)
Expand Up @@ -209,6 +209,12 @@ def subscribe(
# 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/pubsublite_v1/services/subscriber_service/client.py
Expand Up @@ -331,10 +331,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 subscribe(
Expand Down Expand Up @@ -373,6 +370,19 @@ def subscribe(
# 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 @@ -159,6 +159,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 subscribe(
self,
Expand Down
Expand Up @@ -253,5 +253,8 @@ def subscribe(
)
return self._stubs["subscribe"]

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


__all__ = ("SubscriberServiceGrpcTransport",)
Expand Up @@ -258,5 +258,8 @@ def subscribe(
)
return self._stubs["subscribe"]

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


__all__ = ("SubscriberServiceGrpcAsyncIOTransport",)

0 comments on commit 9ad887f

Please sign in to comment.