Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit 3edf825

Browse files
feat: check status of long running operation by its name (#397)
For each client method returning a long running operation, a separate method to check its status is added. Added methods: `checkBatchPredictProgress`, `checkCreateDatasetProgress`, `checkCreateModelProgress`, `checkDeleteDatasetProgress`, `checkDeleteModelProgress`, `checkDeployModelProgress`, `checkExportDataProgress`, `checkExportEvaluatedExamplesProgress`, `checkExportModelProgress`, `checkImportDataProgress`, `checkUndeployModelProgress`.
1 parent 35791ad commit 3edf825

9 files changed

Lines changed: 1590 additions & 241 deletions

src/v1/auto_ml_client.ts

Lines changed: 325 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {Transform} from 'stream';
3232
import {RequestType} from 'google-gax/build/src/apitypes';
3333
import * as protos from '../../protos/protos';
3434
import * as gapicConfig from './auto_ml_client_config.json';
35-
35+
import {operationsProtos} from 'google-gax';
3636
const version = require('../../../package.json').version;
3737

3838
/**
@@ -1074,6 +1074,42 @@ export class AutoMlClient {
10741074
this.initialize();
10751075
return this.innerApiCalls.createDataset(request, options, callback);
10761076
}
1077+
/**
1078+
* Check the status of the long running operation returned by the createDataset() method.
1079+
* @param {String} name
1080+
* The operation name that will be passed.
1081+
* @returns {Promise} - The promise which resolves to an object.
1082+
* The decoded operation object has result and metadata field to get information from.
1083+
*
1084+
* @example:
1085+
* const decodedOperation = await checkCreateDatasetProgress(name);
1086+
* console.log(decodedOperation.result);
1087+
* console.log(decodedOperation.done);
1088+
* console.log(decodedOperation.metadata);
1089+
*
1090+
*/
1091+
async checkCreateDatasetProgress(
1092+
name: string
1093+
): Promise<
1094+
LROperation<
1095+
protos.google.cloud.automl.v1.Dataset,
1096+
protos.google.cloud.automl.v1.OperationMetadata
1097+
>
1098+
> {
1099+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1100+
{name}
1101+
);
1102+
const [operation] = await this.operationsClient.getOperation(request);
1103+
const decodeOperation = new gax.Operation(
1104+
operation,
1105+
this.descriptors.longrunning.createDataset,
1106+
gax.createDefaultBackoffSettings()
1107+
);
1108+
return decodeOperation as LROperation<
1109+
protos.google.cloud.automl.v1.Dataset,
1110+
protos.google.cloud.automl.v1.OperationMetadata
1111+
>;
1112+
}
10771113
deleteDataset(
10781114
request: protos.google.cloud.automl.v1.IDeleteDatasetRequest,
10791115
options?: gax.CallOptions
@@ -1176,6 +1212,42 @@ export class AutoMlClient {
11761212
this.initialize();
11771213
return this.innerApiCalls.deleteDataset(request, options, callback);
11781214
}
1215+
/**
1216+
* Check the status of the long running operation returned by the deleteDataset() method.
1217+
* @param {String} name
1218+
* The operation name that will be passed.
1219+
* @returns {Promise} - The promise which resolves to an object.
1220+
* The decoded operation object has result and metadata field to get information from.
1221+
*
1222+
* @example:
1223+
* const decodedOperation = await checkDeleteDatasetProgress(name);
1224+
* console.log(decodedOperation.result);
1225+
* console.log(decodedOperation.done);
1226+
* console.log(decodedOperation.metadata);
1227+
*
1228+
*/
1229+
async checkDeleteDatasetProgress(
1230+
name: string
1231+
): Promise<
1232+
LROperation<
1233+
protos.google.protobuf.Empty,
1234+
protos.google.cloud.automl.v1.OperationMetadata
1235+
>
1236+
> {
1237+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1238+
{name}
1239+
);
1240+
const [operation] = await this.operationsClient.getOperation(request);
1241+
const decodeOperation = new gax.Operation(
1242+
operation,
1243+
this.descriptors.longrunning.deleteDataset,
1244+
gax.createDefaultBackoffSettings()
1245+
);
1246+
return decodeOperation as LROperation<
1247+
protos.google.protobuf.Empty,
1248+
protos.google.cloud.automl.v1.OperationMetadata
1249+
>;
1250+
}
11791251
importData(
11801252
request: protos.google.cloud.automl.v1.IImportDataRequest,
11811253
options?: gax.CallOptions
@@ -1286,6 +1358,42 @@ export class AutoMlClient {
12861358
this.initialize();
12871359
return this.innerApiCalls.importData(request, options, callback);
12881360
}
1361+
/**
1362+
* Check the status of the long running operation returned by the importData() method.
1363+
* @param {String} name
1364+
* The operation name that will be passed.
1365+
* @returns {Promise} - The promise which resolves to an object.
1366+
* The decoded operation object has result and metadata field to get information from.
1367+
*
1368+
* @example:
1369+
* const decodedOperation = await checkImportDataProgress(name);
1370+
* console.log(decodedOperation.result);
1371+
* console.log(decodedOperation.done);
1372+
* console.log(decodedOperation.metadata);
1373+
*
1374+
*/
1375+
async checkImportDataProgress(
1376+
name: string
1377+
): Promise<
1378+
LROperation<
1379+
protos.google.protobuf.Empty,
1380+
protos.google.cloud.automl.v1.OperationMetadata
1381+
>
1382+
> {
1383+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1384+
{name}
1385+
);
1386+
const [operation] = await this.operationsClient.getOperation(request);
1387+
const decodeOperation = new gax.Operation(
1388+
operation,
1389+
this.descriptors.longrunning.importData,
1390+
gax.createDefaultBackoffSettings()
1391+
);
1392+
return decodeOperation as LROperation<
1393+
protos.google.protobuf.Empty,
1394+
protos.google.cloud.automl.v1.OperationMetadata
1395+
>;
1396+
}
12891397
exportData(
12901398
request: protos.google.cloud.automl.v1.IExportDataRequest,
12911399
options?: gax.CallOptions
@@ -1388,6 +1496,42 @@ export class AutoMlClient {
13881496
this.initialize();
13891497
return this.innerApiCalls.exportData(request, options, callback);
13901498
}
1499+
/**
1500+
* Check the status of the long running operation returned by the exportData() method.
1501+
* @param {String} name
1502+
* The operation name that will be passed.
1503+
* @returns {Promise} - The promise which resolves to an object.
1504+
* The decoded operation object has result and metadata field to get information from.
1505+
*
1506+
* @example:
1507+
* const decodedOperation = await checkExportDataProgress(name);
1508+
* console.log(decodedOperation.result);
1509+
* console.log(decodedOperation.done);
1510+
* console.log(decodedOperation.metadata);
1511+
*
1512+
*/
1513+
async checkExportDataProgress(
1514+
name: string
1515+
): Promise<
1516+
LROperation<
1517+
protos.google.protobuf.Empty,
1518+
protos.google.cloud.automl.v1.OperationMetadata
1519+
>
1520+
> {
1521+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1522+
{name}
1523+
);
1524+
const [operation] = await this.operationsClient.getOperation(request);
1525+
const decodeOperation = new gax.Operation(
1526+
operation,
1527+
this.descriptors.longrunning.exportData,
1528+
gax.createDefaultBackoffSettings()
1529+
);
1530+
return decodeOperation as LROperation<
1531+
protos.google.protobuf.Empty,
1532+
protos.google.cloud.automl.v1.OperationMetadata
1533+
>;
1534+
}
13911535
createModel(
13921536
request: protos.google.cloud.automl.v1.ICreateModelRequest,
13931537
options?: gax.CallOptions
@@ -1492,6 +1636,42 @@ export class AutoMlClient {
14921636
this.initialize();
14931637
return this.innerApiCalls.createModel(request, options, callback);
14941638
}
1639+
/**
1640+
* Check the status of the long running operation returned by the createModel() method.
1641+
* @param {String} name
1642+
* The operation name that will be passed.
1643+
* @returns {Promise} - The promise which resolves to an object.
1644+
* The decoded operation object has result and metadata field to get information from.
1645+
*
1646+
* @example:
1647+
* const decodedOperation = await checkCreateModelProgress(name);
1648+
* console.log(decodedOperation.result);
1649+
* console.log(decodedOperation.done);
1650+
* console.log(decodedOperation.metadata);
1651+
*
1652+
*/
1653+
async checkCreateModelProgress(
1654+
name: string
1655+
): Promise<
1656+
LROperation<
1657+
protos.google.cloud.automl.v1.Model,
1658+
protos.google.cloud.automl.v1.OperationMetadata
1659+
>
1660+
> {
1661+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1662+
{name}
1663+
);
1664+
const [operation] = await this.operationsClient.getOperation(request);
1665+
const decodeOperation = new gax.Operation(
1666+
operation,
1667+
this.descriptors.longrunning.createModel,
1668+
gax.createDefaultBackoffSettings()
1669+
);
1670+
return decodeOperation as LROperation<
1671+
protos.google.cloud.automl.v1.Model,
1672+
protos.google.cloud.automl.v1.OperationMetadata
1673+
>;
1674+
}
14951675
deleteModel(
14961676
request: protos.google.cloud.automl.v1.IDeleteModelRequest,
14971677
options?: gax.CallOptions
@@ -1594,6 +1774,42 @@ export class AutoMlClient {
15941774
this.initialize();
15951775
return this.innerApiCalls.deleteModel(request, options, callback);
15961776
}
1777+
/**
1778+
* Check the status of the long running operation returned by the deleteModel() method.
1779+
* @param {String} name
1780+
* The operation name that will be passed.
1781+
* @returns {Promise} - The promise which resolves to an object.
1782+
* The decoded operation object has result and metadata field to get information from.
1783+
*
1784+
* @example:
1785+
* const decodedOperation = await checkDeleteModelProgress(name);
1786+
* console.log(decodedOperation.result);
1787+
* console.log(decodedOperation.done);
1788+
* console.log(decodedOperation.metadata);
1789+
*
1790+
*/
1791+
async checkDeleteModelProgress(
1792+
name: string
1793+
): Promise<
1794+
LROperation<
1795+
protos.google.protobuf.Empty,
1796+
protos.google.cloud.automl.v1.OperationMetadata
1797+
>
1798+
> {
1799+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1800+
{name}
1801+
);
1802+
const [operation] = await this.operationsClient.getOperation(request);
1803+
const decodeOperation = new gax.Operation(
1804+
operation,
1805+
this.descriptors.longrunning.deleteModel,
1806+
gax.createDefaultBackoffSettings()
1807+
);
1808+
return decodeOperation as LROperation<
1809+
protos.google.protobuf.Empty,
1810+
protos.google.cloud.automl.v1.OperationMetadata
1811+
>;
1812+
}
15971813
deployModel(
15981814
request: protos.google.cloud.automl.v1.IDeployModelRequest,
15991815
options?: gax.CallOptions
@@ -1707,6 +1923,42 @@ export class AutoMlClient {
17071923
this.initialize();
17081924
return this.innerApiCalls.deployModel(request, options, callback);
17091925
}
1926+
/**
1927+
* Check the status of the long running operation returned by the deployModel() method.
1928+
* @param {String} name
1929+
* The operation name that will be passed.
1930+
* @returns {Promise} - The promise which resolves to an object.
1931+
* The decoded operation object has result and metadata field to get information from.
1932+
*
1933+
* @example:
1934+
* const decodedOperation = await checkDeployModelProgress(name);
1935+
* console.log(decodedOperation.result);
1936+
* console.log(decodedOperation.done);
1937+
* console.log(decodedOperation.metadata);
1938+
*
1939+
*/
1940+
async checkDeployModelProgress(
1941+
name: string
1942+
): Promise<
1943+
LROperation<
1944+
protos.google.protobuf.Empty,
1945+
protos.google.cloud.automl.v1.OperationMetadata
1946+
>
1947+
> {
1948+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1949+
{name}
1950+
);
1951+
const [operation] = await this.operationsClient.getOperation(request);
1952+
const decodeOperation = new gax.Operation(
1953+
operation,
1954+
this.descriptors.longrunning.deployModel,
1955+
gax.createDefaultBackoffSettings()
1956+
);
1957+
return decodeOperation as LROperation<
1958+
protos.google.protobuf.Empty,
1959+
protos.google.cloud.automl.v1.OperationMetadata
1960+
>;
1961+
}
17101962
undeployModel(
17111963
request: protos.google.cloud.automl.v1.IUndeployModelRequest,
17121964
options?: gax.CallOptions
@@ -1811,6 +2063,42 @@ export class AutoMlClient {
18112063
this.initialize();
18122064
return this.innerApiCalls.undeployModel(request, options, callback);
18132065
}
2066+
/**
2067+
* Check the status of the long running operation returned by the undeployModel() method.
2068+
* @param {String} name
2069+
* The operation name that will be passed.
2070+
* @returns {Promise} - The promise which resolves to an object.
2071+
* The decoded operation object has result and metadata field to get information from.
2072+
*
2073+
* @example:
2074+
* const decodedOperation = await checkUndeployModelProgress(name);
2075+
* console.log(decodedOperation.result);
2076+
* console.log(decodedOperation.done);
2077+
* console.log(decodedOperation.metadata);
2078+
*
2079+
*/
2080+
async checkUndeployModelProgress(
2081+
name: string
2082+
): Promise<
2083+
LROperation<
2084+
protos.google.protobuf.Empty,
2085+
protos.google.cloud.automl.v1.OperationMetadata
2086+
>
2087+
> {
2088+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
2089+
{name}
2090+
);
2091+
const [operation] = await this.operationsClient.getOperation(request);
2092+
const decodeOperation = new gax.Operation(
2093+
operation,
2094+
this.descriptors.longrunning.undeployModel,
2095+
gax.createDefaultBackoffSettings()
2096+
);
2097+
return decodeOperation as LROperation<
2098+
protos.google.protobuf.Empty,
2099+
protos.google.cloud.automl.v1.OperationMetadata
2100+
>;
2101+
}
18142102
exportModel(
18152103
request: protos.google.cloud.automl.v1.IExportModelRequest,
18162104
options?: gax.CallOptions
@@ -1917,6 +2205,42 @@ export class AutoMlClient {
19172205
this.initialize();
19182206
return this.innerApiCalls.exportModel(request, options, callback);
19192207
}
2208+
/**
2209+
* Check the status of the long running operation returned by the exportModel() method.
2210+
* @param {String} name
2211+
* The operation name that will be passed.
2212+
* @returns {Promise} - The promise which resolves to an object.
2213+
* The decoded operation object has result and metadata field to get information from.
2214+
*
2215+
* @example:
2216+
* const decodedOperation = await checkExportModelProgress(name);
2217+
* console.log(decodedOperation.result);
2218+
* console.log(decodedOperation.done);
2219+
* console.log(decodedOperation.metadata);
2220+
*
2221+
*/
2222+
async checkExportModelProgress(
2223+
name: string
2224+
): Promise<
2225+
LROperation<
2226+
protos.google.protobuf.Empty,
2227+
protos.google.cloud.automl.v1.OperationMetadata
2228+
>
2229+
> {
2230+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
2231+
{name}
2232+
);
2233+
const [operation] = await this.operationsClient.getOperation(request);
2234+
const decodeOperation = new gax.Operation(
2235+
operation,
2236+
this.descriptors.longrunning.exportModel,
2237+
gax.createDefaultBackoffSettings()
2238+
);
2239+
return decodeOperation as LROperation<
2240+
protos.google.protobuf.Empty,
2241+
protos.google.cloud.automl.v1.OperationMetadata
2242+
>;
2243+
}
19202244
listDatasets(
19212245
request: protos.google.cloud.automl.v1.IListDatasetsRequest,
19222246
options?: gax.CallOptions

0 commit comments

Comments
 (0)