Skip to content

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 de71591 commit 917f0e7
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 48 deletions.
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
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
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
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
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 packages/google-cloud-videointelligence/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
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 917f0e7

Please sign in to comment.