forked from elastic/makelogs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (55 loc) · 1.55 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Notify user of updates
*/
var pkg = require('./package.json');
require('update-notifier')({ packageName: pkg.name, packageVersion: pkg.version }).notify();
var Promise = require('bluebird');
var client = require('./_client');
var randomEvent = require('./_randomEvent');
var samples = require('./samples');
var eventBuffer = require('./eventBuffer');
var createIndex = require('./_createIndex');
var argv = require('./argv');
var total = argv.total;
var startingMoment = argv.start;
var endingMoment = argv.end;
var indexPrefix = argv.indexPrefix;
client.usable
.then(function () {
console.log('Generating', total, 'events from', startingMoment.format(), 'to', endingMoment.format());
})
.then(function () {
if (argv.dry) return;
return createIndex();
})
.then(function () {
argv.log('creating', total, 'events');
var i = total;
return (function crunch() {
argv.log('creating no more than', i, 'events');
for (; i >= 0; i--) {
var event = randomEvent(indexPrefix);
if (argv.dry) {
console.log('\n\n', event);
continue;
}
// eventBuffer.push might return a promise,
var delay = eventBuffer.push({
header: { _index: event.index, _type: 'doc' },
body: event
});
if (delay) {
argv.log('waiting for bulk to complete');
// stop the loop and restart once complete
return Promise.resolve(delay).then(crunch);
}
}
}());
})
.then(function () {
if (argv.dry) return;
eventBuffer.push(false);
})
.catch(function (err) {
console.error(err.stack);
});