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

Function main

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

Source from the content-addressed store, hash-verified

17'use strict';
18
19async function main() {
20 // [START batch_create_local_ssd_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-local-ssd-job';
39 // The name of a local SSD created for this job.
40 const localSsdName = 'ssd-name';
41 // The machine type, which can be predefined or custom, of the job's VMs.
42 // The allowed number of local SSDs depends on the machine type
43 // for your job's VMs are listed on: https://cloud.google.com/compute/docs/disks#localssds
44 const machineType = 'c3d-standard-8-lssd';
45 // The size of all the local SSDs in GB. Each local SSD is 375 GB,
46 // so this value must be a multiple of 375 GB.
47 // For example, for 2 local SSDs, set this value to 750 GB.
48 const ssdSize = 375;
49
50 // Define what will be done as part of the job.
51 const runnable = new batch.Runnable({
52 script: new batch.Runnable.Script({
53 commands: [
54 '-c',
55 'echo Hello world! This is task ${BATCH_TASK_INDEX}. This job has a total of ${BATCH_TASK_COUNT} tasks.',
56 ],
57 }),
58 });
59
60 const task = new batch.TaskSpec({
61 runnables: [runnable],
62 maxRetryCount: 2,
63 maxRunDuration: {seconds: 3600},
64 });
65
66 // Tasks are grouped inside a job using TaskGroups.
67 const group = new batch.TaskGroup({
68 taskCount: 3,
69 taskSpec: task,
70 });
71
72 // Policies are used to define on what kind of virtual machines the tasks will run on.
73 const instancePolicy = new batch.AllocationPolicy.InstancePolicy({
74 machineType,
75 disks: [
76 new batch.AllocationPolicy.AttachedDisk({

Callers 1

Calls 2

getProjectIdMethod · 0.80
callCreateBatchGPUJobFunction · 0.70

Tested by

no test coverage detected