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

Commit

Permalink
feat: add context manager support in client (#104)
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 824009a commit 2c5f07d
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 8 deletions.
Expand Up @@ -776,6 +776,12 @@ async def delete_job_template(
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
Expand Up @@ -372,10 +372,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 @@ -979,6 +976,19 @@ def delete_job_template(
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 @@ -182,6 +182,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_job(
self,
Expand Down
Expand Up @@ -437,5 +437,8 @@ def delete_job_template(
)
return self._stubs["delete_job_template"]

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


__all__ = ("TranscoderServiceGrpcTransport",)
Expand Up @@ -446,5 +446,8 @@ def delete_job_template(
)
return self._stubs["delete_job_template"]

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


__all__ = ("TranscoderServiceGrpcAsyncIOTransport",)
27 changes: 27 additions & 0 deletions google/cloud/video/transcoder_v1/types/resources.py
Expand Up @@ -47,6 +47,7 @@

class Job(proto.Message):
r"""Transcoding job resource.
Attributes:
name (str):
The resource name of the job. Format:
Expand Down Expand Up @@ -123,6 +124,7 @@ class ProcessingState(proto.Enum):

class JobTemplate(proto.Message):
r"""Transcoding job template resource.
Attributes:
name (str):
The resource name of the job template. Format:
Expand All @@ -137,6 +139,7 @@ class JobTemplate(proto.Message):

class JobConfig(proto.Message):
r"""Job configuration
Attributes:
inputs (Sequence[google.cloud.video.transcoder_v1.types.Input]):
List of input assets stored in Cloud Storage.
Expand Down Expand Up @@ -182,6 +185,7 @@ class JobConfig(proto.Message):

class Input(proto.Message):
r"""Input asset.
Attributes:
key (str):
A unique key for this input. Must be
Expand All @@ -205,6 +209,7 @@ class Input(proto.Message):

class Output(proto.Message):
r"""Location of output file(s) in a Cloud Storage bucket.
Attributes:
uri (str):
URI for the output file(s). For example,
Expand All @@ -217,6 +222,7 @@ class Output(proto.Message):

class EditAtom(proto.Message):
r"""Edit atom.
Attributes:
key (str):
A unique key for this atom. Must be specified
Expand Down Expand Up @@ -246,6 +252,7 @@ class EditAtom(proto.Message):

class AdBreak(proto.Message):
r"""Ad break.
Attributes:
start_time_offset (google.protobuf.duration_pb2.Duration):
Start time in seconds for the ad break, relative to the
Expand Down Expand Up @@ -288,6 +295,7 @@ class ElementaryStream(proto.Message):

class MuxStream(proto.Message):
r"""Multiplexing settings for output stream.
Attributes:
key (str):
A unique key for this multiplexed stream. HLS media
Expand Down Expand Up @@ -326,6 +334,7 @@ class MuxStream(proto.Message):

class Manifest(proto.Message):
r"""Manifest configuration.
Attributes:
file_name (str):
The name of the generated file. The default is ``manifest``
Expand Down Expand Up @@ -355,6 +364,7 @@ class ManifestType(proto.Enum):

class PubsubDestination(proto.Message):
r"""A Pub/Sub destination.
Attributes:
topic (str):
The name of the Pub/Sub topic to publish job completion
Expand Down Expand Up @@ -454,6 +464,7 @@ class SpriteSheet(proto.Message):

class Overlay(proto.Message):
r"""Overlay configuration.
Attributes:
image (google.cloud.video.transcoder_v1.types.Overlay.Image):
Image overlay.
Expand All @@ -470,6 +481,7 @@ class FadeType(proto.Enum):

class NormalizedCoordinate(proto.Message):
r"""2D normalized coordinates. Default: ``{0.0, 0.0}``
Attributes:
x (float):
Normalized x coordinate.
Expand All @@ -482,6 +494,7 @@ class NormalizedCoordinate(proto.Message):

class Image(proto.Message):
r"""Overlaid jpeg image.
Attributes:
uri (str):
Required. URI of the JPEG image in Cloud Storage. For
Expand All @@ -507,6 +520,7 @@ class Image(proto.Message):

class AnimationStatic(proto.Message):
r"""Display static overlay object.
Attributes:
xy (google.cloud.video.transcoder_v1.types.Overlay.NormalizedCoordinate):
Normalized coordinates based on output video resolution.
Expand All @@ -529,6 +543,7 @@ class AnimationStatic(proto.Message):

class AnimationFade(proto.Message):
r"""Display overlay object with fade animation.
Attributes:
fade_type (google.cloud.video.transcoder_v1.types.Overlay.FadeType):
Required. Type of fade animation: ``FADE_IN`` or
Expand Down Expand Up @@ -576,6 +591,7 @@ class AnimationEnd(proto.Message):

class Animation(proto.Message):
r"""Animation types.
Attributes:
animation_static (google.cloud.video.transcoder_v1.types.Overlay.AnimationStatic):
Display static overlay object.
Expand Down Expand Up @@ -610,6 +626,7 @@ class Animation(proto.Message):

class PreprocessingConfig(proto.Message):
r"""Preprocessing configurations.
Attributes:
color (google.cloud.video.transcoder_v1.types.PreprocessingConfig.Color):
Color preprocessing configuration.
Expand All @@ -627,6 +644,7 @@ class PreprocessingConfig(proto.Message):

class Color(proto.Message):
r"""Color preprocessing configuration.
Attributes:
saturation (float):
Control color saturation of the video. Enter
Expand All @@ -651,6 +669,7 @@ class Color(proto.Message):

class Denoise(proto.Message):
r"""Denoise preprocessing configuration.
Attributes:
strength (float):
Set strength of the denoise. Enter a value
Expand All @@ -671,6 +690,7 @@ class Denoise(proto.Message):

class Deblock(proto.Message):
r"""Deblock preprocessing configuration.
Attributes:
strength (float):
Set strength of the deblocker. Enter a value
Expand All @@ -686,6 +706,7 @@ class Deblock(proto.Message):

class Audio(proto.Message):
r"""Audio preprocessing configuration.
Attributes:
lufs (float):
Specify audio loudness normalization in loudness units
Expand Down Expand Up @@ -772,6 +793,7 @@ class Pad(proto.Message):

class VideoStream(proto.Message):
r"""Video stream resource.
Attributes:
h264 (google.cloud.video.transcoder_v1.types.VideoStream.H264CodecSettings):
H264 codec settings.
Expand All @@ -783,6 +805,7 @@ class VideoStream(proto.Message):

class H264CodecSettings(proto.Message):
r"""H264 codec settings.
Attributes:
width_pixels (int):
The width of the video in pixels. Must be an
Expand Down Expand Up @@ -931,6 +954,7 @@ class H264CodecSettings(proto.Message):

class H265CodecSettings(proto.Message):
r"""H265 codec settings.
Attributes:
width_pixels (int):
The width of the video in pixels. Must be an
Expand Down Expand Up @@ -1091,6 +1115,7 @@ class H265CodecSettings(proto.Message):

class Vp9CodecSettings(proto.Message):
r"""VP9 codec settings.
Attributes:
width_pixels (int):
The width of the video in pixels. Must be an
Expand Down Expand Up @@ -1193,6 +1218,7 @@ class Vp9CodecSettings(proto.Message):

class AudioStream(proto.Message):
r"""Audio stream resource.
Attributes:
codec (str):
The codec for this audio stream. The default is ``aac``.
Expand Down Expand Up @@ -1318,6 +1344,7 @@ class TextMapping(proto.Message):

class SegmentSettings(proto.Message):
r"""Segment settings for ``ts``, ``fmp4`` and ``vtt``.
Attributes:
segment_duration (google.protobuf.duration_pb2.Duration):
Duration of the segments in seconds. The default is
Expand Down
9 changes: 9 additions & 0 deletions google/cloud/video/transcoder_v1/types/services.py
Expand Up @@ -37,6 +37,7 @@

class CreateJobRequest(proto.Message):
r"""Request message for ``TranscoderService.CreateJob``.
Attributes:
parent (str):
Required. The parent location to create and process this
Expand Down Expand Up @@ -81,6 +82,7 @@ class ListJobsRequest(proto.Message):

class GetJobRequest(proto.Message):
r"""Request message for ``TranscoderService.GetJob``.
Attributes:
name (str):
Required. The name of the job to retrieve. Format:
Expand All @@ -92,6 +94,7 @@ class GetJobRequest(proto.Message):

class DeleteJobRequest(proto.Message):
r"""Request message for ``TranscoderService.DeleteJob``.
Attributes:
name (str):
Required. The name of the job to delete. Format:
Expand All @@ -108,6 +111,7 @@ class DeleteJobRequest(proto.Message):

class ListJobsResponse(proto.Message):
r"""Response message for ``TranscoderService.ListJobs``.
Attributes:
jobs (Sequence[google.cloud.video.transcoder_v1.types.Job]):
List of jobs in the specified region.
Expand All @@ -128,6 +132,7 @@ def raw_page(self):

class CreateJobTemplateRequest(proto.Message):
r"""Request message for ``TranscoderService.CreateJobTemplate``.
Attributes:
parent (str):
Required. The parent location to create this job template.
Expand All @@ -152,6 +157,7 @@ class CreateJobTemplateRequest(proto.Message):

class ListJobTemplatesRequest(proto.Message):
r"""Request message for ``TranscoderService.ListJobTemplates``.
Attributes:
parent (str):
Required. The parent location from which to retrieve the
Expand Down Expand Up @@ -180,6 +186,7 @@ class ListJobTemplatesRequest(proto.Message):

class GetJobTemplateRequest(proto.Message):
r"""Request message for ``TranscoderService.GetJobTemplate``.
Attributes:
name (str):
Required. The name of the job template to retrieve. Format:
Expand All @@ -191,6 +198,7 @@ class GetJobTemplateRequest(proto.Message):

class DeleteJobTemplateRequest(proto.Message):
r"""Request message for ``TranscoderService.DeleteJobTemplate``.
Attributes:
name (str):
Required. The name of the job template to delete.
Expand All @@ -207,6 +215,7 @@ class DeleteJobTemplateRequest(proto.Message):

class ListJobTemplatesResponse(proto.Message):
r"""Response message for ``TranscoderService.ListJobTemplates``.
Attributes:
job_templates (Sequence[google.cloud.video.transcoder_v1.types.JobTemplate]):
List of job templates in the specified
Expand Down
Expand Up @@ -775,6 +775,12 @@ async def delete_job_template(
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

0 comments on commit 2c5f07d

Please sign in to comment.