-
Notifications
You must be signed in to change notification settings - Fork 0
/
poller.js
39 lines (25 loc) · 942 Bytes
/
poller.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
var fs = require('fs')
, amqp = require('amqp')
, elasticsearch = require('elasticsearch')
, runner = require('./lib/runner');
// load configuration file
var conf = JSON.parse(fs.readFileSync('./config.js').toString())
, elasticsearch_client = new elasticsearch.Client(conf.elastic)
, amqp_connection = amqp.createConnection(conf.amqp);
var files = fs.readdirSync('./queries.d/');
console.log('waiting for amqp connection');
var booted = false;
amqp_connection.on('ready', function () {
if (booted) {
return;
}
booted = true;
console.log('amqp connection established.');
for(var i in files) {
console.log('loading elastic query: ' + files[i]);
var file = './queries.d/' + files[i];
var data = JSON.parse(fs.readFileSync(file).toString());
run = new runner(elasticsearch_client, amqp_connection, data);
run.run();
}
});