Skip to content

Commit

Permalink
feat: check status of long running operation by its name (#773)
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: `checkAsyncBatchAnnotateFilesProgress`, `checkAsyncBatchAnnotateImagesProgress`, `checkImportProductSetsProgress`, `checkPurgeProductsProgress`.
  • Loading branch information
alexander-fenster authored May 6, 2020
1 parent 226cdcf commit ff95d40
Show file tree
Hide file tree
Showing 17 changed files with 2,044 additions and 1,344 deletions.
2,086 changes: 1,043 additions & 1,043 deletions packages/google-cloud-vision/protos/protos.js

Large diffs are not rendered by default.

74 changes: 73 additions & 1 deletion packages/google-cloud-vision/src/v1/image_annotator_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 './image_annotator_client_config.json';

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

/**
Expand Down Expand Up @@ -684,6 +684,42 @@ export class ImageAnnotatorClient {
callback
);
}
/**
* Check the status of the long running operation returned by the asyncBatchAnnotateImages() 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 checkAsyncBatchAnnotateImagesProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAsyncBatchAnnotateImagesProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.vision.v1.AsyncBatchAnnotateImagesResponse,
protos.google.cloud.vision.v1.OperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.asyncBatchAnnotateImages,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.vision.v1.AsyncBatchAnnotateImagesResponse,
protos.google.cloud.vision.v1.OperationMetadata
>;
}
asyncBatchAnnotateFiles(
request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest,
options?: gax.CallOptions
Expand Down Expand Up @@ -804,6 +840,42 @@ export class ImageAnnotatorClient {
callback
);
}
/**
* Check the status of the long running operation returned by the asyncBatchAnnotateFiles() 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 checkAsyncBatchAnnotateFilesProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAsyncBatchAnnotateFilesProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse,
protos.google.cloud.vision.v1.OperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.asyncBatchAnnotateFiles,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse,
protos.google.cloud.vision.v1.OperationMetadata
>;
}
// --------------------
// -- Path templates --
// --------------------
Expand Down
74 changes: 73 additions & 1 deletion packages/google-cloud-vision/src/v1/product_search_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {Transform} from 'stream';
import {RequestType} from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
import * as gapicConfig from './product_search_client_config.json';

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

/**
Expand Down Expand Up @@ -1782,6 +1782,42 @@ export class ProductSearchClient {
this.initialize();
return this.innerApiCalls.importProductSets(request, options, callback);
}
/**
* Check the status of the long running operation returned by the importProductSets() 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 checkImportProductSetsProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkImportProductSetsProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.vision.v1.ImportProductSetsResponse,
protos.google.cloud.vision.v1.BatchOperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.importProductSets,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.vision.v1.ImportProductSetsResponse,
protos.google.cloud.vision.v1.BatchOperationMetadata
>;
}
purgeProducts(
request: protos.google.cloud.vision.v1.IPurgeProductsRequest,
options?: gax.CallOptions
Expand Down Expand Up @@ -1913,6 +1949,42 @@ export class ProductSearchClient {
this.initialize();
return this.innerApiCalls.purgeProducts(request, options, callback);
}
/**
* Check the status of the long running operation returned by the purgeProducts() 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 checkPurgeProductsProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkPurgeProductsProgress(
name: string
): Promise<
LROperation<
protos.google.protobuf.Empty,
protos.google.cloud.vision.v1.BatchOperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.purgeProducts,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.protobuf.Empty,
protos.google.cloud.vision.v1.BatchOperationMetadata
>;
}
listProductSets(
request: protos.google.cloud.vision.v1.IListProductSetsRequest,
options?: gax.CallOptions
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 './image_annotator_client_config.json';

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

/**
Expand Down Expand Up @@ -504,6 +504,42 @@ export class ImageAnnotatorClient {
callback
);
}
/**
* Check the status of the long running operation returned by the asyncBatchAnnotateFiles() 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 checkAsyncBatchAnnotateFilesProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAsyncBatchAnnotateFilesProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse,
protos.google.cloud.vision.v1p2beta1.OperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.asyncBatchAnnotateFiles,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse,
protos.google.cloud.vision.v1p2beta1.OperationMetadata
>;
}

/**
* 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 './image_annotator_client_config.json';

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

/**
Expand Down Expand Up @@ -520,6 +520,42 @@ export class ImageAnnotatorClient {
callback
);
}
/**
* Check the status of the long running operation returned by the asyncBatchAnnotateFiles() 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 checkAsyncBatchAnnotateFilesProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkAsyncBatchAnnotateFilesProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.vision.v1p3beta1.AsyncBatchAnnotateFilesResponse,
protos.google.cloud.vision.v1p3beta1.OperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.asyncBatchAnnotateFiles,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.vision.v1p3beta1.AsyncBatchAnnotateFilesResponse,
protos.google.cloud.vision.v1p3beta1.OperationMetadata
>;
}
// --------------------
// -- Path templates --
// --------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {Transform} from 'stream';
import {RequestType} from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
import * as gapicConfig from './product_search_client_config.json';

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

/**
Expand Down Expand Up @@ -1859,6 +1859,42 @@ export class ProductSearchClient {
this.initialize();
return this.innerApiCalls.importProductSets(request, options, callback);
}
/**
* Check the status of the long running operation returned by the importProductSets() 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 checkImportProductSetsProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkImportProductSetsProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.vision.v1p3beta1.ImportProductSetsResponse,
protos.google.cloud.vision.v1p3beta1.BatchOperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.importProductSets,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.vision.v1p3beta1.ImportProductSetsResponse,
protos.google.cloud.vision.v1p3beta1.BatchOperationMetadata
>;
}
listProductSets(
request: protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest,
options?: gax.CallOptions
Expand Down
Loading

0 comments on commit ff95d40

Please sign in to comment.