()
| 17 | 'use strict'; |
| 18 | |
| 19 | async function main() { |
| 20 | // [START batch_labels_job] |
| 21 | // Imports the Batch library |
| 22 | const batchLib = require('@google-cloud/batch'); |
| 23 | const batch = batchLib.protos.google.cloud.batch.v1; |
| 24 | |
| 25 | // Instantiates a client |
| 26 | const batchClient = new batchLib.v1.BatchServiceClient(); |
| 27 | |
| 28 | /** |
| 29 | * TODO(developer): Update these variables before running the sample. |
| 30 | */ |
| 31 | // Project ID or project number of the Google Cloud project you want to use. |
| 32 | const projectId = await batchClient.getProjectId(); |
| 33 | // Name of the region you want to use to run the job. Regions that are |
| 34 | // available for Batch are listed on: https://cloud.google.com/batch/docs/get-started#locations |
| 35 | const region = 'europe-central2'; |
| 36 | // The name of the job that will be created. |
| 37 | // It needs to be unique for each project and region pair. |
| 38 | const jobName = 'batch-labels-job'; |
| 39 | // Name of the label1 to be applied for your Job. |
| 40 | const labelName1 = 'job_label_name_1'; |
| 41 | // Value for the label1 to be applied for your Job. |
| 42 | const labelValue1 = 'job_label_value1'; |
| 43 | // Name of the label2 to be applied for your Job. |
| 44 | const labelName2 = 'job_label_name_2'; |
| 45 | // Value for the label2 to be applied for your Job. |
| 46 | const labelValue2 = 'job_label_value2'; |
| 47 | |
| 48 | // Define what will be done as part of the job. |
| 49 | const runnable = new batch.Runnable({ |
| 50 | container: new batch.Runnable.Container({ |
| 51 | imageUri: 'gcr.io/google-containers/busybox', |
| 52 | entrypoint: '/bin/sh', |
| 53 | commands: ['-c', 'echo Hello world! This is task ${BATCH_TASK_INDEX}.'], |
| 54 | }), |
| 55 | }); |
| 56 | |
| 57 | // Specify what resources are requested by each task. |
| 58 | const computeResource = new batch.ComputeResource({ |
| 59 | // In milliseconds per cpu-second. This means the task requires 50% of a single CPUs. |
| 60 | cpuMilli: 500, |
| 61 | // In MiB. |
| 62 | memoryMib: 16, |
| 63 | }); |
| 64 | |
| 65 | const task = new batch.TaskSpec({ |
| 66 | runnables: [runnable], |
| 67 | computeResource, |
| 68 | maxRetryCount: 2, |
| 69 | maxRunDuration: {seconds: 3600}, |
| 70 | }); |
| 71 | |
| 72 | // Tasks are grouped inside a job using TaskGroups. |
| 73 | const group = new batch.TaskGroup({ |
| 74 | taskCount: 3, |
| 75 | taskSpec: task, |
| 76 | }); |
no test coverage detected