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

Commit

Permalink
feat: add context manager support in client (#168)
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 48c7627 commit 04dd991
Show file tree
Hide file tree
Showing 95 changed files with 1,142 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,12 @@ async def list_companies(
# 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/talent_v4/services/company_service/client.py
Original file line number Diff line number Diff line change
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 create_company(
Expand Down Expand Up @@ -785,6 +782,19 @@ def list_companies(
# 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 @@ -211,6 +211,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 create_company(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,8 @@ def list_companies(
)
return self._stubs["list_companies"]

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


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

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


__all__ = ("CompanyServiceGrpcAsyncIOTransport",)
6 changes: 6 additions & 0 deletions google/cloud/talent_v4/services/completion/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ async def complete_query(
# 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/talent_v4/services/completion/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,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 complete_query(
Expand Down Expand Up @@ -410,6 +407,19 @@ def complete_query(
# 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
9 changes: 9 additions & 0 deletions google/cloud/talent_v4/services/completion/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,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 complete_query(
self,
Expand Down
3 changes: 3 additions & 0 deletions google/cloud/talent_v4/services/completion/transports/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,8 @@ def complete_query(
)
return self._stubs["complete_query"]

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


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

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


__all__ = ("CompletionGrpcAsyncIOTransport",)
6 changes: 6 additions & 0 deletions google/cloud/talent_v4/services/event_service/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ async def create_client_event(
# 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/talent_v4/services/event_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,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_client_event(
Expand Down Expand Up @@ -445,6 +442,19 @@ def create_client_event(
# 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 @@ -161,6 +161,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 create_client_event(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,8 @@ def create_client_event(
)
return self._stubs["create_client_event"]

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


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

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


__all__ = ("EventServiceGrpcAsyncIOTransport",)
6 changes: 6 additions & 0 deletions google/cloud/talent_v4/services/job_service/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,12 @@ async def search_jobs_for_alert(
# 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/talent_v4/services/job_service/client.py
Original file line number Diff line number Diff line change
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_job(
Expand Down Expand Up @@ -1238,6 +1235,19 @@ def search_jobs_for_alert(
# 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 @@ -230,6 +230,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
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,8 @@ def search_jobs_for_alert(
)
return self._stubs["search_jobs_for_alert"]

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


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

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


__all__ = ("JobServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ async def list_tenants(
# 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/talent_v4/services/tenant_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,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_tenant(
Expand Down Expand Up @@ -763,6 +760,19 @@ def list_tenants(
# 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