Skip to content

Commit

Permalink
feat: check status of long running operation by its name; fix linting (
Browse files Browse the repository at this point in the history
…#531)

For each client method returning a long running operation, a separate method to check its status is added.

Added methods: `checkBatchTranslateTextProgress`, `checkCreateGlossaryProgress`, `checkDeleteGlossaryProgress`.
  • Loading branch information
alexander-fenster authored May 6, 2020
1 parent 8519e77 commit 0646ba6
Show file tree
Hide file tree
Showing 8 changed files with 819 additions and 395 deletions.
604 changes: 302 additions & 302 deletions packages/google-cloud-translate/protos/protos.js

Large diffs are not rendered by default.

110 changes: 109 additions & 1 deletion packages/google-cloud-translate/src/v3/translation_service_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 './translation_service_client_config.json';

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

/**
Expand Down Expand Up @@ -999,6 +999,42 @@ export class TranslationServiceClient {
this.initialize();
return this.innerApiCalls.batchTranslateText(request, options, callback);
}
/**
* Check the status of the long running operation returned by the batchTranslateText() 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 checkBatchTranslateTextProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkBatchTranslateTextProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.translation.v3.BatchTranslateResponse,
protos.google.cloud.translation.v3.BatchTranslateMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.batchTranslateText,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.translation.v3.BatchTranslateResponse,
protos.google.cloud.translation.v3.BatchTranslateMetadata
>;
}
createGlossary(
request: protos.google.cloud.translation.v3.ICreateGlossaryRequest,
options?: gax.CallOptions
Expand Down Expand Up @@ -1100,6 +1136,42 @@ export class TranslationServiceClient {
this.initialize();
return this.innerApiCalls.createGlossary(request, options, callback);
}
/**
* Check the status of the long running operation returned by the createGlossary() 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 checkCreateGlossaryProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkCreateGlossaryProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.translation.v3.Glossary,
protos.google.cloud.translation.v3.CreateGlossaryMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.createGlossary,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.translation.v3.Glossary,
protos.google.cloud.translation.v3.CreateGlossaryMetadata
>;
}
deleteGlossary(
request: protos.google.cloud.translation.v3.IDeleteGlossaryRequest,
options?: gax.CallOptions
Expand Down Expand Up @@ -1200,6 +1272,42 @@ export class TranslationServiceClient {
this.initialize();
return this.innerApiCalls.deleteGlossary(request, options, callback);
}
/**
* Check the status of the long running operation returned by the deleteGlossary() 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 checkDeleteGlossaryProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkDeleteGlossaryProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.translation.v3.DeleteGlossaryResponse,
protos.google.cloud.translation.v3.DeleteGlossaryMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.deleteGlossary,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.translation.v3.DeleteGlossaryResponse,
protos.google.cloud.translation.v3.DeleteGlossaryMetadata
>;
}
listGlossaries(
request: protos.google.cloud.translation.v3.IListGlossariesRequest,
options?: gax.CallOptions
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 './translation_service_client_config.json';

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

/**
Expand Down Expand Up @@ -1012,6 +1012,42 @@ export class TranslationServiceClient {
this.initialize();
return this.innerApiCalls.batchTranslateText(request, options, callback);
}
/**
* Check the status of the long running operation returned by the batchTranslateText() 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 checkBatchTranslateTextProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkBatchTranslateTextProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.translation.v3beta1.BatchTranslateResponse,
protos.google.cloud.translation.v3beta1.BatchTranslateMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.batchTranslateText,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.translation.v3beta1.BatchTranslateResponse,
protos.google.cloud.translation.v3beta1.BatchTranslateMetadata
>;
}
createGlossary(
request: protos.google.cloud.translation.v3beta1.ICreateGlossaryRequest,
options?: gax.CallOptions
Expand Down Expand Up @@ -1113,6 +1149,42 @@ export class TranslationServiceClient {
this.initialize();
return this.innerApiCalls.createGlossary(request, options, callback);
}
/**
* Check the status of the long running operation returned by the createGlossary() 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 checkCreateGlossaryProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkCreateGlossaryProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.translation.v3beta1.Glossary,
protos.google.cloud.translation.v3beta1.CreateGlossaryMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.createGlossary,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.translation.v3beta1.Glossary,
protos.google.cloud.translation.v3beta1.CreateGlossaryMetadata
>;
}
deleteGlossary(
request: protos.google.cloud.translation.v3beta1.IDeleteGlossaryRequest,
options?: gax.CallOptions
Expand Down Expand Up @@ -1213,6 +1285,42 @@ export class TranslationServiceClient {
this.initialize();
return this.innerApiCalls.deleteGlossary(request, options, callback);
}
/**
* Check the status of the long running operation returned by the deleteGlossary() 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 checkDeleteGlossaryProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkDeleteGlossaryProgress(
name: string
): Promise<
LROperation<
protos.google.cloud.translation.v3beta1.DeleteGlossaryResponse,
protos.google.cloud.translation.v3beta1.DeleteGlossaryMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.deleteGlossary,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.cloud.translation.v3beta1.DeleteGlossaryResponse,
protos.google.cloud.translation.v3beta1.DeleteGlossaryMetadata
>;
}
listGlossaries(
request: protos.google.cloud.translation.v3beta1.IListGlossariesRequest,
options?: gax.CallOptions
Expand Down
14 changes: 3 additions & 11 deletions packages/google-cloud-translate/synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
{
"git": {
"name": ".",
"remote": "https://github.com/googleapis/nodejs-translate.git",
"sha": "3f593aab5d8d9ff16350b203d4b8ec315b0c8ad7"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "42ee97c1b93a0e3759bbba3013da309f670a90ab",
"internalRef": "307114445"
"remote": "[email protected]:googleapis/nodejs-translate.git",
"sha": "87160cda48ff8a13e5891f24118b94162da0f6f7"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "19465d3ec5e5acdb01521d8f3bddd311bcbee28d"
"sha": "ab883569eb0257bbf16a6d825fd018b3adde3912"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-translate/system-test/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('translate', () => {
let err: Error | null = null;
try {
const projectId = await translate.getProjectId();
const [result] = await translate.getSupportedLanguages({
await translate.getSupportedLanguages({
parent: `projects/${projectId}`,
});
} catch (_err) {
Expand Down
Loading

0 comments on commit 0646ba6

Please sign in to comment.