Skip to content

Commit 74cd805

Browse files
committed
Add a get_task sample for batch
1 parent 4aa917d commit 74cd805

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

batch/get/get_task.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Retrieves information about the specified job, most notably its status.
19+
*
20+
* @param {string} projectId - ID or number of the Google Cloud project you want to use.
21+
* @param {string} region - The Google Cloud region to use, e.g. 'us-central1'
22+
* @param {string} jobName - ID used to uniquely identify the Job within this project and region.
23+
* This field should contain at most 63 characters.
24+
* Only alphanumeric characters or '-' are accepted.
25+
* The '-' character cannot be the first or the last one.
26+
* @param {string} groupName - the name of the group that owns the task you want to check.
27+
* Usually it's `group0`.
28+
* @param {number} taskNumber - number of the task you want to look up.
29+
*/
30+
function main(projectId, region, jobName, groupName, taskNumber) {
31+
// [START batch_get_task]
32+
/**
33+
* TODO(developer): Uncomment and replace these variables before running the sample.
34+
*/
35+
// const projectId = 'YOUR_PROJECT_ID';
36+
/**
37+
* The region that hosts the job.
38+
*/
39+
// const region = 'us-central-1';
40+
/**
41+
* The name of the job you want to retrieve information about.
42+
*/
43+
// const jobName = 'YOUR_JOB_NAME';
44+
/**
45+
* the name of the group that owns the task you want to check.
46+
* Usually it's `group0`.
47+
*/
48+
// const groupName = 'group0';
49+
/**
50+
* number of the task you want to look up.
51+
*/
52+
// const taskNumber = 0;
53+
54+
// Imports the Batch library
55+
const batchLib = require('@google-cloud/batch');
56+
57+
// Instantiates a client
58+
const batchClient = new batchLib.v1.BatchServiceClient();
59+
60+
async function callGetJob() {
61+
// Construct request
62+
const request = {
63+
name: `projects/${projectId}/locations/${region}/jobs/${jobName}` +
64+
`/taskGroups/${groupName}/tasks/${taskNumber}`,
65+
};
66+
67+
// Run request
68+
const response = await batchClient.getTask(request);
69+
console.log(response);
70+
}
71+
72+
callGetJob();
73+
// [END batch_get_task]
74+
}
75+
76+
process.on('unhandledRejection', err => {
77+
console.error(err.message);
78+
process.exitCode = 1;
79+
});
80+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)