-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathexportRegistrationsJob.ts
More file actions
54 lines (44 loc) · 1.77 KB
/
exportRegistrationsJob.ts
File metadata and controls
54 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample demonstrates how the createNotificationJob() method can be used to export registrations
* descriptions so that they can be imported into another Azure Notification Hub.
*
* See https://learn.microsoft.com/azure/notification-hubs/export-modify-registrations-bulk
* to learn about Export and Import Registrations in Azure Notification Hubs.
*
*
* @summary Demonstrates how to export registrations from a Notification Hub.
* @azsdk-weight 100
*/
import "dotenv/config";
import {
createClientContext,
getNotificationHubJob,
submitNotificationHubJob,
} from "@azure/notification-hubs/api";
import type { NotificationHubJob } from "@azure/notification-hubs/models";
import { delay } from "@azure/core-util";
// Define connection string and hub name
const connectionString = process.env.NOTIFICATIONHUBS_CONNECTION_STRING || "<connection string>";
const hubName = process.env.NOTIFICATION_HUB_NAME || "<hub name>";
// Define export job parameters
const outputContainerUrl = process.env.OUTPUT_CONTAINER_URL || "<output container URL>";
async function main(): Promise<void> {
const context = createClientContext(connectionString, hubName);
let exportJob: NotificationHubJob = {
outputContainerUrl,
type: "ExportRegistrations",
};
exportJob = await submitNotificationHubJob(context, exportJob);
let count = 0;
while (exportJob.status !== "Completed" && exportJob.status !== "Failed" && count++ < 10) {
exportJob = await getNotificationHubJob(context, exportJob.jobId!);
await delay(1000);
}
console.log(`Notification Hub Job status: ${exportJob.status}`);
}
main().catch((err) => {
console.log("exportRegistrationJob Sample: Error occurred: ", err);
process.exit(1);
});