-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph-launcher.js
49 lines (37 loc) · 1.13 KB
/
graph-launcher.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
var restify = require('restify');
var cluster = require('cluster');
var graph = require('./graph.js');
var numCores = require('os').cpus().length;
if (cluster.isMaster) {
var workers = [];
for ( var i = 0; i < numCores; i++) {
workers.push(cluster.fork());
}
cluster.on('death', function(worker) {
console.log('Worker ' + worker.pid + ' died');
});
function shutdown() {
console.log("Closing...");
graph.shutdown();
while (worker = workers.pop()) {
console.log('Killing child ' + worker.pid);
worker.kill('SIGQUIT');
}
process.exit(0);
}
process.on('SIGTERM', shutdown);
} else {
var server = restify.createServer();
server.use(restify.acceptParser(server.acceptable));
server.use(restify.bodyParser());
server.get('/:id/following', graph.following);
server.post('/:id/following', graph.postFollowing);
server.listen(8080, function() {
var milliseconds = new Date().getTime();
console.log('%d - %s listening at %s', milliseconds, server.name, server.url);
});
process.on('SIGQUIT', function() {
console.log('Killing restify...');
server.close();
});
}