Created
April 9, 2014 19:59
-
-
Save jmervine/10308492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install restify | |
var payload = JSON.parse(require('fs').readFileSync('./bento.json', 'utf8')); | |
var cluster = require('cluster'); | |
if (cluster.isMaster) { | |
cluster.fork(); | |
cluster.fork(); | |
cluster.on('exit', function() { | |
console.log('starting new fork'); | |
cluster.fork(); | |
}); | |
} else { | |
var restify = require('restify'); | |
var server = restify.createServer(); | |
function handle(req, res, next) { | |
if (Math.random() > 0.8) { | |
setTimeout(function() { | |
process.exit(); | |
}, 3000); | |
} else { | |
setTimeout(function() { | |
res.json(payload); | |
next(); | |
}, 500); | |
} | |
} | |
server.get(/.*/, handle); | |
server.listen(8888); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment