12.0.0 • Published 10 months ago

@azure/batch v12.0.0

Weekly downloads
508
License
MIT
Repository
github
Last release
10 months ago

Azure BatchServiceClient SDK for JavaScript

This package contains an isomorphic SDK for BatchServiceClient.

Currently supported environments

See our support policy for more details.

How to Install

npm install @azure/batch

How to use

nodejs - Authentication, client creation and list application as an example written in TypeScript.

Install @azure/ms-rest-nodeauth
npm install @azure/ms-rest-nodeauth
Authentication
  1. Use the BatchSharedKeyCredentials exported from @azure/batch.
import { BatchServiceClient, BatchSharedKeyCredentials } from "@azure/batch";

const batchAccountName = process.env["AZURE_BATCH_ACCOUNT_NAME"] || "";
const batchAccountKey = process.env["AZURE_BATCH_ACCOUNT_KEY"] || "";
const batchEndpoint = process.env["AZURE_BATCH_ENDPOINT"] || "";

async function main(): Promise<void> {
  try {
    const creds = new BatchSharedKeyCredentials(batchAccountName, batchAccountKey);
    const client = new BatchServiceClient(creds, batchEndpoint);
  } catch (err) {
    console.log(err);
  }
}
  1. Use the MSIVmTokenCredentials exported from @azure/ms-rest-nodeauth.
import { BatchServiceClient } from "@azure/batch";
import { loginWithVmMSI } from "@azure/ms-rest-nodeauth";

const batchEndpoint = process.env["AZURE_BATCH_ENDPOINT"] || "";

async function main(): Promise<void> {
  try {
    const creds = await loginWithVmMSI({
      resource: "https://batch.core.windows.net/"
    });
    const client = new BatchServiceClient(creds, batchEndpoint);
  } catch (err) {
    console.log(err);
  }
}
Sample code
import { BatchServiceClient, BatchServiceModels, BatchSharedKeyCredentials } from "@azure/batch";

const batchAccountName = process.env["AZURE_BATCH_ACCOUNT_NAME"] || "";
const batchAccountKey = process.env["AZURE_BATCH_ACCOUNT_KEY"] || "";
const batchEndpoint = process.env["AZURE_BATCH_ENDPOINT"] || "";

const creds = new BatchSharedKeyCredentials(batchAccountName, batchAccountKey);
const client = new BatchServiceClient(creds, batchEndpoint);

const options: BatchServiceModels.JobListOptionalParams = {
  jobListOptions: { maxResults: 10 }
};

async function loop(res: BatchServiceModels.JobListResponse, nextLink?: string): Promise<void> {
  if (nextLink !== undefined) {
    const res1 = await client.job.listNext(nextLink);
    if (res1.length) {
      for (const item of res1) {
        res.push(item);
      }
    }
    return loop(res, res1.odatanextLink);
  }
  return Promise.resolve();
}

async function main(): Promise<void> {
  const result = await client.job.list(options);
  await loop(result, result.odatanextLink);
  console.dir(result, { depth: null, colors: true });
}

main().catch((err) => console.log("An error occurred: ", err));

Related projects

Impressions

12.0.0

10 months ago

11.1.0

1 year ago

11.0.0

2 years ago

10.2.0

3 years ago

10.1.0

3 years ago

10.0.2

4 years ago

10.0.1

4 years ago

10.0.0

4 years ago

9.0.0

4 years ago

8.0.0

5 years ago

7.0.0

6 years ago

6.0.0

6 years ago

0.1.0

7 years ago

1.0.0

7 years ago