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

Function main

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

Source from the content-addressed store, hash-verified

17'use strict';
18
19async function main() {
20 // [START batch_create_nfs_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-nfs-job';
39 // The path of the NFS directory that you want this job to access.
40 const nfsPath = '/your_nfs_path';
41 // The IP address of the Network File System.
42 const nfsIpAddress = '0.0.0.0';
43 // The mount path that the job's tasks use to access the NFS.
44 const mountPath = '/mnt/disks';
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: [
50 '-c',
51 'echo Hello world from task ${BATCH_TASK_INDEX}. >> ' +
52 '/mnt/share/output_task_${BATCH_TASK_INDEX}.txt',
53 ],
54 }),
55 });
56
57 // Define a volume that uses NFS.
58 const volume = new batch.Volume({
59 nfs: new batch.NFS({
60 server: nfsIpAddress,
61 remotePath: nfsPath,
62 }),
63 mountPath,
64 });
65
66 // Specify what resources are requested by each task.
67 const computeResource = new batch.ComputeResource({
68 // In milliseconds per cpu-second. This means the task requires 50% of a single CPUs.
69 cpuMilli: 500,
70 // In MiB.
71 memoryMib: 16,
72 });
73
74 const task = new batch.TaskSpec({
75 runnables: [runnable],
76 volumes: [volume],

Callers 1

create_nfs_job.jsFile · 0.70

Calls 2

callCreateBatchNfsJobFunction · 0.85
getProjectIdMethod · 0.80

Tested by

no test coverage detected