()
| 17 | 'use strict'; |
| 18 | |
| 19 | async function main() { |
| 20 | // [START batch_custom_events] |
| 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-custom-events-job'; |
| 39 | // Name of the runnable, which must be unique |
| 40 | // within the job. For example: script 1, barrier 1, and script 2. |
| 41 | const displayName1 = 'script 1'; |
| 42 | const displayName2 = 'barrier 1'; |
| 43 | const displayName3 = 'script 2'; |
| 44 | |
| 45 | // Create runnables with custom scripts |
| 46 | const runnable1 = new batch.Runnable({ |
| 47 | displayName: displayName1, |
| 48 | script: new batch.Runnable.Script({ |
| 49 | commands: [ |
| 50 | '-c', |
| 51 | 'echo Hello world from script 1 for task ${BATCH_TASK_INDEX}.', |
| 52 | ], |
| 53 | }), |
| 54 | }); |
| 55 | |
| 56 | const runnable2 = new batch.Runnable({ |
| 57 | displayName: displayName2, |
| 58 | barrier: new batch.Runnable.Barrier(), |
| 59 | }); |
| 60 | |
| 61 | const runnable3 = new batch.Runnable({ |
| 62 | displayName: displayName3, |
| 63 | script: new batch.Runnable.Script({ |
| 64 | // Replace DESCRIPTION with a description |
| 65 | // for the custom status event—for example, halfway done. |
| 66 | commands: [ |
| 67 | 'sleep 30; echo \'{"batch/custom/event": "DESCRIPTION"}\'; sleep 30', |
| 68 | ], |
| 69 | }), |
| 70 | }); |
| 71 | |
| 72 | const task = new batch.TaskSpec({ |
| 73 | runnables: [runnable1, runnable2, runnable3], |
| 74 | maxRetryCount: 2, |
| 75 | maxRunDuration: {seconds: 3600}, |
| 76 | }); |
no test coverage detected