Pass context from gRPC streams to background tasks

This commit is contained in:
Rob Watson 2022-02-05 07:44:44 +01:00
parent 6dde29cdcf
commit 54e9bc0d2c
1 changed files with 3 additions and 3 deletions

View File

@ -53,7 +53,7 @@ func (c *mediaSetServiceController) Get(ctx context.Context, request *pbmediaset
// part of the MediaSet.
func (c *mediaSetServiceController) GetPeaks(request *pbmediaset.GetPeaksRequest, stream pbmediaset.MediaSetService_GetPeaksServer) error {
// TODO: reduce timeout when fetching from S3
ctx, cancel := context.WithTimeout(context.Background(), getPeaksTimeout)
ctx, cancel := context.WithTimeout(stream.Context(), getPeaksTimeout)
defer cancel()
id, err := uuid.Parse(request.GetId())
@ -118,7 +118,7 @@ func (c *mediaSetServiceController) GetPeaksForSegment(ctx context.Context, requ
}
func (c *mediaSetServiceController) GetAudioSegment(request *pbmediaset.GetAudioSegmentRequest, outStream pbmediaset.MediaSetService_GetAudioSegmentServer) error {
ctx, cancel := context.WithTimeout(context.Background(), getPeaksForSegmentTimeout)
ctx, cancel := context.WithTimeout(outStream.Context(), getPeaksForSegmentTimeout)
defer cancel()
id, err := uuid.Parse(request.GetId())
@ -164,7 +164,7 @@ func (c *mediaSetServiceController) GetAudioSegment(request *pbmediaset.GetAudio
func (c *mediaSetServiceController) GetVideo(request *pbmediaset.GetVideoRequest, stream pbmediaset.MediaSetService_GetVideoServer) error {
// TODO: reduce timeout when already fetched from Youtube
ctx, cancel := context.WithTimeout(context.Background(), getVideoTimeout)
ctx, cancel := context.WithTimeout(stream.Context(), getVideoTimeout)
defer cancel()
id, err := uuid.Parse(request.GetId())