-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (31 loc) · 1018 Bytes
/
index.js
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
'use strict';
var matches,
fs = require('fs'),
URMonitorSet = require(__dirname + '/lib/URMonitorSet'),
urlFile = fs.readFileSync(__dirname + '/http-urls-to-monitor.txt', 'utf8'),
lines = urlFile.split('\n');
URMonitorSet.getMonitors((monitors) => {
if (monitors.length) {
monitors.forEach((monitor, i) => {
// be kind to UR and make 1 request per sec
setTimeout(() => {
URMonitorSet.deleteMonitor(monitor);
}, i * 1000);
});
}
var checkIfDeletionsComplete = setInterval(() => {
if (!URMonitorSet.pendingDeleteRequests) {
clearInterval(checkIfDeletionsComplete);
lines.forEach((currentLine, i) => {
// be kind to UR and make 1 request per sec
setTimeout(() => {
if (matches = currentLine.match(/^\s*"([^"]+)"\s+"([^"]+)"/)) {
URMonitorSet.newMonitor(matches[1], matches[2]);
}
},i * 1000);
});
} else {
console.log('Waiting for deletions to complete.');
}
}, 1000);
});