-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.js
executable file
·79 lines (71 loc) · 1.51 KB
/
run.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Haystack 0.0.2
// (c) 2014 Simon Swain
// Haystack may be freely distributed under the MIT license.
// https://github.com/simonswain/haystack
var straw = require('straw');
var config = require('./config/config.js');
var opts = {
nodes_dir: __dirname + '/nodes',
redis: config.redis
};
var cls = function(){
process.stdout.write('\u001B[2J\u001B[0;0f');
};
var topo = straw.create(opts);
topo.add([{
id: 'consume-firehose',
node: 'consume-firehose',
output: 'raw-tweets',
twitter: config.twitter
}, {
id: 'route-tweets',
node: 'route-tweets',
input: 'raw-tweets',
outputs: {
geo: 'client-geo',
lang: 'lang',
text: 'text'
}
}, {
id: 'catch-langs',
node: 'catch-langs',
input: 'lang',
output: 'langs'
}, {
id: 'catch-text',
node: 'catch-text',
input: 'text',
outputs:{
// words :'words',
// urls :'urls',
hashtags:'hashtags'
}
}, {
id: 'catch-hashtags',
node: 'catch-hashtags',
input: 'hashtags',
output: 'client-hashtags'
}, {
id: 'client-langs',
node: 'passthru',
input: 'langs',
output: 'client-langs'
}], function(){
topo.start({purge: true});
});
var stats = function(){
topo.stats(function(err, data){
cls();
console.log(new Date());
// stats.nodes show input/output counts
// stats.pipes show unprocessed messages in pipe
console.log(data);
});
};
var interval = setInterval(stats, 1000);
process.on( 'SIGINT', function() {
clearInterval(interval);
topo.destroy(function(){
console.log( 'Finished.' );
});
});