-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
47 lines (34 loc) · 1.06 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
"use strict"; // Use ES6
const request = require('request');
console.log("Node.js Event Queue Service");
console.log("Conecting to http://" + process.env.KNOWN_DOMAIN);
var Service = require("./Service.js");
var ServiceCaller = new Service();
const { execSync } = require('child_process');
var pjson = require('./package.json');
// Main loop
setInterval(() => {
var listquery = {
url: 'http://' + process.env.KNOWN_DOMAIN + '/service/queue/list/',
method: 'GET',
json: true,
};
ServiceCaller.call(listquery, function(call, hash) {
call.headers = {
'X-KNOWN-SERVICE-SIGNATURE': hash
}
request(call, (err, res, body) => {
if (err) {
return console.error(err);
}
if (('' + res.statusCode).match(/^5\d\d$/)) {
console.error("EXCEPTION: " + body.exception.message);
return;
}
for (var index in body.queue) {
console.log("Dispatching event: " + body.queue[index]);
execSync(pjson.knownpath + 'known.php event-queue-manage default dispatch ' + body.queue[index]);
}
});
});
}, 5000);