MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

batch/create/create_batch_custom_network.js:19–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17'use strict';
18
19async function main() {
20 // [START batch_create_custom_network]
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 = 'example-job';
39 // The name of a VPC network in the current project or a Shared VPC network that is hosted by
40 // or shared with the current project.
41 const network = 'global/networks/test-network';
42 // The name of a subnetwork that is part of the VPC network and is located
43 // in the same region as the VMs for the job.
44 const subnetwork = `regions/${region}/subnetworks/subnet`;
45
46 // Define what will be done as part of the job.
47 const runnable = new batch.Runnable({
48 script: new batch.Runnable.Script({
49 commands: ['-c', 'echo Hello world! This is task ${BATCH_TASK_INDEX}.'],
50 }),
51 });
52
53 // Specify what resources are requested by each task.
54 const computeResource = new batch.ComputeResource({
55 // In milliseconds per cpu-second. This means the task requires 50% of a single CPUs.
56 cpuMilli: 500,
57 // In MiB.
58 memoryMib: 16,
59 });
60
61 const task = new batch.TaskSpec({
62 runnables: [runnable],
63 computeResource,
64 maxRetryCount: 2,
65 maxRunDuration: {seconds: 3600},
66 });
67
68 // Tasks are grouped inside a job using TaskGroups.
69 const group = new batch.TaskGroup({
70 taskCount: 3,
71 taskSpec: task,
72 });
73
74 // Specify VPC network and a subnet for Allocation Policy
75 const networkPolicy = new batch.AllocationPolicy.NetworkPolicy({
76 networkInterfaces: [

Callers 1

Calls 2

getProjectIdMethod · 0.80

Tested by

no test coverage detected