-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathimportRegistrationsJob.js
More file actions
54 lines (44 loc) · 1.72 KB
/
importRegistrationsJob.js
File metadata and controls
54 lines (44 loc) · 1.72 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 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.
*/
require("dotenv/config");
const {
createClientContext,
getNotificationHubJob,
submitNotificationHubJob,
} = require("@azure/notification-hubs/api");
const { delay } = require("@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() {
const context = createClientContext(connectionString, hubName);
let importJob = {
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);
});