-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathimportRegistrationsJob.ts
More file actions
56 lines (46 loc) · 1.84 KB
/
importRegistrationsJob.ts
File metadata and controls
56 lines (46 loc) · 1.84 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
55
56
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample demonstrates how the createNotificationJob() method can be used to import registrations
* descriptions from an existing set of exports.
*
* 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 import registrations into 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>";
const importFileUrl = process.env.IMPORT_FILE_URL || "<import file URL>";
async function main(): Promise<void> {
const context = createClientContext(connectionString, hubName);
let importJob: NotificationHubJob = {
outputContainerUrl,
importFileUrl,
type: "ImportCreateRegistrations",
};
importJob = await submitNotificationHubJob(context, importJob);
let count = 0;
while (importJob.status !== "Completed" && importJob.status !== "Failed" && count++ < 10) {
importJob = await getNotificationHubJob(context, importJob.jobId!);
await delay(1000);
}
console.log(`Notification Hub Job status: ${importJob.status}`);
}
main().catch((err) => {
console.log("exportRegistrationJob Sample: Error occurred: ", err);
process.exit(1);
});