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

feat: add context manager support in client #230

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
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",)
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",)
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
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
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
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",)
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",)
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
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
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
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",)
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",)
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
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
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
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",)
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",)
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
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
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
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",)
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",)