koa-cluster
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,3 +5,2 @@ | ||
var http = require('http') | ||
var domain = require('domain') | ||
var cluster = require('cluster') | ||
@@ -15,6 +14,6 @@ | ||
var server = http.createServer() | ||
server.on('request', handler) | ||
server.on('request', callback) | ||
server.on('checkContinue', function (req, res) { | ||
req.checkContinue = true | ||
handler(req, res) | ||
callback(req, res) | ||
}) | ||
@@ -37,34 +36,16 @@ | ||
var closing = false | ||
process.on('SIGTERM', close) | ||
process.on('SIGINT', close) | ||
process.on('SIGTERM', function () { | ||
close(0) | ||
}) | ||
process.on('SIGINT', function () { | ||
close(0) | ||
}) | ||
process.on('uncaughtException', function (err) { | ||
console.error(err.stack) | ||
close(1) | ||
}) | ||
process.on('exit', function () { | ||
console.log('process exiting') | ||
console.log('exiting worker %s', cluster.worker.id) | ||
}) | ||
// http://nodejs.org/api/domain.html | ||
function handler(req, res) { | ||
var d = domain.create() | ||
d.on('error', function (err) { | ||
console.error(err.stack) | ||
close(1) | ||
try { | ||
res.statusCode = 500 | ||
res.setHeader('Content-Type', 'text/plain') | ||
res.end('Oops, sorry!') | ||
} catch (err) { | ||
console.error(err.stack) | ||
} | ||
}) | ||
d.add(req) | ||
d.add(res) | ||
d.run(function () { | ||
callback(req, res) | ||
}) | ||
} | ||
function close(code) { | ||
@@ -77,3 +58,3 @@ if (closing) return | ||
var killtimer = setTimeout(function () { | ||
process.exit(code || 0) | ||
process.exit(code) | ||
}, 30000) | ||
@@ -80,0 +61,0 @@ |
{ | ||
"name": "koa-cluster", | ||
"description": "Koa clustering and domain-based error handling utility", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Jonathan Ong", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6208
51