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

Commit

Permalink
feat: add context manager support in client (#230)
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 c7d369b commit 954dd18
Show file tree
Hide file tree
Showing 53 changed files with 671 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,12 @@ async def update_alert_policy(
# 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/monitoring_v3/services/alert_policy_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,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_alert_policies(
Expand Down Expand Up @@ -840,6 +837,19 @@ def update_alert_policy(
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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_alert_policies(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,8 @@ def update_alert_policy(
)
return self._stubs["update_alert_policy"]

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


__all__ = ("AlertPolicyServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -379,5 +379,8 @@ def update_alert_policy(
)
return self._stubs["update_alert_policy"]

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


__all__ = ("AlertPolicyServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,12 @@ async def list_group_members(
# 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/monitoring_v3/services/group_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,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_groups(
Expand Down Expand Up @@ -917,6 +914,19 @@ def list_group_members(
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,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_groups(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,8 @@ def list_group_members(
)
return self._stubs["list_group_members"]

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


__all__ = ("GroupServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,8 @@ def list_group_members(
)
return self._stubs["list_group_members"]

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


__all__ = ("GroupServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,12 @@ async def create_time_series(
request, retry=retry, timeout=timeout, metadata=metadata,
)

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/monitoring_v3/services/metric_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,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_monitored_resource_descriptors(
Expand Down Expand Up @@ -1116,6 +1113,19 @@ def create_time_series(
request, retry=retry, timeout=timeout, metadata=metadata,
)

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
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,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_monitored_resource_descriptors(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,5 +471,8 @@ def create_time_series(
)
return self._stubs["create_time_series"]

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


__all__ = ("MetricServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -479,5 +479,8 @@ def create_time_series(
)
return self._stubs["create_time_series"]

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


__all__ = ("MetricServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,12 @@ async def verify_notification_channel(
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,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_notification_channel_descriptors(
Expand Down Expand Up @@ -1328,6 +1325,19 @@ def verify_notification_channel(
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,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_notification_channel_descriptors(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,5 +574,8 @@ def verify_notification_channel(
)
return self._stubs["verify_notification_channel"]

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


__all__ = ("NotificationChannelServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,8 @@ def verify_notification_channel(
)
return self._stubs["verify_notification_channel"]

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


__all__ = ("NotificationChannelServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ async def query_time_series(
# 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/monitoring_v3/services/query_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,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 query_time_series(
Expand Down Expand Up @@ -394,6 +391,19 @@ def query_time_series(
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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 query_time_series(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,8 @@ def query_time_series(
)
return self._stubs["query_time_series"]

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


__all__ = ("QueryServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,8 @@ def query_time_series(
)
return self._stubs["query_time_series"]

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


__all__ = ("QueryServiceGrpcAsyncIOTransport",)
Loading

0 comments on commit 954dd18

Please sign in to comment.