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 (#114)
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: `checkCreateBuildProgress`, `checkRetryBuildProgress`, `checkRunBuildTriggerProgress`.
  • Loading branch information
alexander-fenster authored May 6, 2020
1 parent 7b55f19 commit 7b50a74
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 76 deletions.
110 changes: 109 additions & 1 deletion src/v1/cloud_build_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 './cloud_build_client_config.json';

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

/**
Expand Down Expand Up @@ -1462,6 +1462,42 @@ export class CloudBuildClient {
this.initialize();
return this.innerApiCalls.createBuild(request, options, callback);
}
/**
* Check the status of the long running operation returned by the createBuild() 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 checkCreateBuildProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkCreateBuildProgress(
name: string
): Promise<
LROperation<
protos.google.devtools.cloudbuild.v1.Build,
protos.google.devtools.cloudbuild.v1.BuildOperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.createBuild,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.devtools.cloudbuild.v1.Build,
protos.google.devtools.cloudbuild.v1.BuildOperationMetadata
>;
}
retryBuild(
request: protos.google.devtools.cloudbuild.v1.IRetryBuildRequest,
options?: gax.CallOptions
Expand Down Expand Up @@ -1588,6 +1624,42 @@ export class CloudBuildClient {
this.initialize();
return this.innerApiCalls.retryBuild(request, options, callback);
}
/**
* Check the status of the long running operation returned by the retryBuild() 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 checkRetryBuildProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkRetryBuildProgress(
name: string
): Promise<
LROperation<
protos.google.devtools.cloudbuild.v1.Build,
protos.google.devtools.cloudbuild.v1.BuildOperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.retryBuild,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.devtools.cloudbuild.v1.Build,
protos.google.devtools.cloudbuild.v1.BuildOperationMetadata
>;
}
runBuildTrigger(
request: protos.google.devtools.cloudbuild.v1.IRunBuildTriggerRequest,
options?: gax.CallOptions
Expand Down Expand Up @@ -1690,6 +1762,42 @@ export class CloudBuildClient {
this.initialize();
return this.innerApiCalls.runBuildTrigger(request, options, callback);
}
/**
* Check the status of the long running operation returned by the runBuildTrigger() 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 checkRunBuildTriggerProgress(name);
* console.log(decodedOperation.result);
* console.log(decodedOperation.done);
* console.log(decodedOperation.metadata);
*
*/
async checkRunBuildTriggerProgress(
name: string
): Promise<
LROperation<
protos.google.devtools.cloudbuild.v1.Build,
protos.google.devtools.cloudbuild.v1.BuildOperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.runBuildTrigger,
gax.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.devtools.cloudbuild.v1.Build,
protos.google.devtools.cloudbuild.v1.BuildOperationMetadata
>;
}
listBuilds(
request: protos.google.devtools.cloudbuild.v1.IListBuildsRequest,
options?: gax.CallOptions
Expand Down
14 changes: 3 additions & 11 deletions 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-cloudbuild.git",
"sha": "eaa52923d28e6f61c425f7d40a29a15305de9c86"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "42ee97c1b93a0e3759bbba3013da309f670a90ab",
"internalRef": "307114445"
"remote": "git@github.com:googleapis/nodejs-cloudbuild.git",
"sha": "7b55f19b90423b4e1ab4db41707ad26b036cb935"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "19465d3ec5e5acdb01521d8f3bddd311bcbee28d"
"sha": "ab883569eb0257bbf16a6d825fd018b3adde3912"
}
}
],
Expand Down
Loading

0 comments on commit 7b50a74

Please sign in to comment.