Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make in-flight registry more generic, accommodate more than just requ…

…est/response.
  • Loading branch information...
commit 70f579e3919b2391673ff3e369c6fda681f4326d 1 parent 89a5ee7
Matthew Eernisse mde authored
Showing with 38 additions and 41 deletions.
  1. +31 −2 lib/app.js
  2. +4 −3 lib/cluster/worker.js
  3. +3 −36 lib/in_flight.js
33 lib/app.js
View
@@ -235,7 +235,8 @@ var App = function () {
, sessions: false
}
, finish
- , accessTime = (new Date()).getTime();
+ , accessTime = (new Date()).getTime()
+ , inFlighId;
finish = function (step) {
steps[step] = true;
@@ -270,7 +271,35 @@ var App = function () {
// Okay, let's be anal and force all the HTTP verbs to uppercase
method = method.toUpperCase();
- geddy.inFlight.addEntry(req, method, resp, accessTime);
+ inFlightId = geddy.inFlight.addEntry({
+ request: req
+ , method: method
+ , response: resp
+ , accessTime: accessTime
+ });
+ req._geddyId = inFlightId;
+ resp._geddyId = inFlightId;
+
+ // FIXME: Holy shit, all inline here
+ resp.addListener('finish', function () {
+ var id = resp._geddyId
+ , entry = geddy.inFlight.getEntry(id)
+ , req = entry.request
+ , stat = resp.statusCode
+ , level = parseInt(stat, 10) > 499 ? 'error' : 'access';
+ // Apache extended log-format
+ geddy.log[level](req.connection.remoteAddress + ' ' +
+ '- ' +
+ '- ' +
+ '[' + new Date(entry.accessTime) + '] ' +
+ '"' + entry.method + ' ' + req.url + ' ' +
+ req.httpVersion + '" ' +
+ stat + ' ' +
+ (resp._length || '-') + ' ' +
+ '"' + (req.headers['referer'] || '-') + '" ' +
+ '"' + (req.headers['user-agent'] || '-') + '" ');
+ geddy.inFlight.removeEntry(id);
+ });
params = router.first(req, method);
}
7 lib/cluster/worker.js
View
@@ -84,11 +84,12 @@ Worker.prototype = new (function () {
ready = (new Date()).getTime() - startTime >
self.config.gracefulShutdownTimeout;
if (ready) {
- // Unceremoniously end any outstanding responses
- // FIXME: What shoud the statusCode be on these?
+ // Unceremoniously end responses in the in-flight registry
geddy.inFlight.each(function (entry) {
try {
- entry.response.end();
+ if (entry.response) {
+ entry.response.end();
+ }
}
// Squelch, the process is going down anyhow
catch(e) {}
39 lib/in_flight.js
View
@@ -6,17 +6,10 @@ var InFlight = function () {
InFlight.prototype = new (function () {
- this.addEntry = function (req, method, resp, accessTime) {
+ this.addEntry = function (data) {
var id = geddy.string.uuid();
- req._geddyId = id;
- resp._geddyId = id;
- this.entries.addItem(id, {
- request: req
- , method: method
- , response: resp
- , accessTime: accessTime
- });
- this.addListeners(req, resp);
+ this.entries.addItem(id, data);
+ return id;
};
this.updateEntry = function (id, obj) {
@@ -39,32 +32,6 @@ InFlight.prototype = new (function () {
this.entries.each(handler);
};
- this.finalize = function (resp) {
- var id = resp._geddyId
- , entry = this.entries.getItem(id)
- , req = entry.request
- , stat = resp.statusCode
- , level = parseInt(stat, 10) > 499 ? 'error' : 'access';
- // Apache extended log-format
- geddy.log[level](req.connection.remoteAddress + ' ' +
- '- ' +
- '- ' +
- '[' + new Date(entry.accessTime) + '] ' +
- '"' + entry.method + ' ' + req.url + ' ' +
- req.httpVersion + '" ' +
- stat + ' ' +
- (resp._length || '-') + ' ' +
- '"' + (req.headers['referer'] || '-') + '" ' +
- '"' + (req.headers['user-agent'] || '-') + '" ');
- this.removeEntry(id);
- };
-
- this.addListeners = function (req, resp) {
- var self = this;
- resp.addListener('finish', function () {
- self.finalize(resp);
- });
- };
})();
module.exports.InFlight = InFlight;
Please sign in to comment.
Something went wrong with that request. Please try again.