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

Commit

Permalink
feat: check status of long running operation by its name (#435)
Browse files Browse the repository at this point in the history
For each client method returning a long running operation, a separate method to check its status is added.

Added methods: `checkAnnotateVideoProgress`.
  • Loading branch information
alexander-fenster authored May 6, 2020
1 parent 604fdd6 commit be4793e
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 48 deletions.
38 changes: 37 additions & 1 deletion src/v1/video_intelligence_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as path from 'path';

import * as protos from '../../protos/protos';
import * as gapicConfig from './video_intelligence_service_client_config.json';

import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -430,6 +430,42 @@ export class VideoIntelligenceServiceClient {
this.initialize();
return this.innerApiCalls.annotateVideo(request, options, callback);
}
/**
* Check the status of the long running operation returned by the annotateVideo() method.
* @param {String} name
* The operation name that will be passed.
* @returns {Promise} - The promise which resolves to an object.
* The decoded operation object has result and metadata field to get information from.
*
* @example:
* const decodedOperation = await checkAnnotateVideoProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAnnotateVideoProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.videointelligence.v1.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1.AnnotateVideoProgress
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.annotateVideo,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.videointelligence.v1.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1.AnnotateVideoProgress
>;
}

/**
* Terminate the GRPC channel and close the client.
Expand Down
38 changes: 37 additions & 1 deletion src/v1beta2/video_intelligence_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as path from 'path';

import * as protos from '../../protos/protos';
import * as gapicConfig from './video_intelligence_service_client_config.json';

import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -430,6 +430,42 @@ export class VideoIntelligenceServiceClient {
this.initialize();
return this.innerApiCalls.annotateVideo(request, options, callback);
}
/**
* Check the status of the long running operation returned by the annotateVideo() method.
* @param {String} name
* The operation name that will be passed.
* @returns {Promise} - The promise which resolves to an object.
* The decoded operation object has result and metadata field to get information from.
*
* @example:
* const decodedOperation = await checkAnnotateVideoProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAnnotateVideoProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.videointelligence.v1beta2.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1beta2.AnnotateVideoProgress
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.annotateVideo,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.videointelligence.v1beta2.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1beta2.AnnotateVideoProgress
>;
}

/**
* Terminate the GRPC channel and close the client.
Expand Down
38 changes: 37 additions & 1 deletion src/v1p1beta1/video_intelligence_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as path from 'path';

import * as protos from '../../protos/protos';
import * as gapicConfig from './video_intelligence_service_client_config.json';

import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -430,6 +430,42 @@ export class VideoIntelligenceServiceClient {
this.initialize();
return this.innerApiCalls.annotateVideo(request, options, callback);
}
/**
* Check the status of the long running operation returned by the annotateVideo() method.
* @param {String} name
* The operation name that will be passed.
* @returns {Promise} - The promise which resolves to an object.
* The decoded operation object has result and metadata field to get information from.
*
* @example:
* const decodedOperation = await checkAnnotateVideoProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAnnotateVideoProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoProgress
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.annotateVideo,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1p1beta1.AnnotateVideoProgress
>;
}

/**
* Terminate the GRPC channel and close the client.
Expand Down
38 changes: 37 additions & 1 deletion src/v1p2beta1/video_intelligence_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as path from 'path';

import * as protos from '../../protos/protos';
import * as gapicConfig from './video_intelligence_service_client_config.json';

import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -430,6 +430,42 @@ export class VideoIntelligenceServiceClient {
this.initialize();
return this.innerApiCalls.annotateVideo(request, options, callback);
}
/**
* Check the status of the long running operation returned by the annotateVideo() method.
* @param {String} name
* The operation name that will be passed.
* @returns {Promise} - The promise which resolves to an object.
* The decoded operation object has result and metadata field to get information from.
*
* @example:
* const decodedOperation = await checkAnnotateVideoProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAnnotateVideoProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoProgress
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.annotateVideo,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1p2beta1.AnnotateVideoProgress
>;
}

/**
* Terminate the GRPC channel and close the client.
Expand Down
38 changes: 37 additions & 1 deletion src/v1p3beta1/video_intelligence_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as path from 'path';

import * as protos from '../../protos/protos';
import * as gapicConfig from './video_intelligence_service_client_config.json';

import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -430,6 +430,42 @@ export class VideoIntelligenceServiceClient {
this.initialize();
return this.innerApiCalls.annotateVideo(request, options, callback);
}
/**
* Check the status of the long running operation returned by the annotateVideo() method.
* @param {String} name
* The operation name that will be passed.
* @returns {Promise} - The promise which resolves to an object.
* The decoded operation object has result and metadata field to get information from.
*
* @example:
* const decodedOperation = await checkAnnotateVideoProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAnnotateVideoProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoProgress
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.annotateVideo,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoResponse,
protos.google.cloud.videointelligence.v1p3beta1.AnnotateVideoProgress
>;
}

/**
* Terminate the GRPC channel and close the client.
Expand Down
10 changes: 5 additions & 5 deletions synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
{
"git": {
"name": ".",
"remote": "https://github.com/googleapis/nodejs-video-intelligence.git",
"sha": "3b5ad804802d391c2e1d1e575b700d3d69391ef5"
"remote": "git@github.com:googleapis/nodejs-video-intelligence.git",
"sha": "1c520fcba901d09902dc7f1fe73d150c8ddeee00"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "42ee97c1b93a0e3759bbba3013da309f670a90ab",
"internalRef": "307114445"
"sha": "a3a0bf0f6291d69f2ff3df7fcd63d28ee20ac727",
"internalRef": "310060413"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "19465d3ec5e5acdb01521d8f3bddd311bcbee28d"
"sha": "ab883569eb0257bbf16a6d825fd018b3adde3912"
}
}
],
Expand Down
4 changes: 1 addition & 3 deletions test/gapic_streaming_video_intelligence_service_v1p3beta1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ describe('v1p3beta1.StreamingVideoIntelligenceServiceClient', () => {
stream.write(request);
stream.end();
});
await assert.rejects(async () => {
await promise;
}, expectedError);
await assert.rejects(promise, expectedError);
assert(
(client.innerApiCalls.streamingAnnotateVideo as SinonStub)
.getCall(0)
Expand Down
Loading

0 comments on commit be4793e

Please sign in to comment.