Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A bit more cleanup to the startup.

  • Loading branch information...
commit 45d927623057936fcd62227111b794b725e84927 1 parent de944ab
@mde mde authored
View
12 bin/cli.js
@@ -7,6 +7,7 @@ var fs = require('fs')
, exec = require('child_process').exec
, parseopts = require('../lib/parseopts')
, utils = require('../lib/utils/index')
+ , App = require('../lib/app.js').App
, parser
, args = process.argv.slice(2)
, optsReg
@@ -71,7 +72,8 @@ var start = function () {
, master
, worker
, m
- , w;
+ , w
+ , app;
// Node 0.6
try {
@@ -95,8 +97,12 @@ var start = function () {
}
// Worker-process -- start up an app
else {
- var App = require('../lib/app.js').App;
- var app = new App();
+ w = new worker.Worker();
+ geddy.mixin(geddy, w);
+ app = new App();
+ app.init(function () {
+ w.startServer();
+ });
geddy.mixin(geddy, app);
}
View
46 lib/app.js
@@ -19,7 +19,9 @@
var fs = require('fs')
, url = require('url')
, querystring = require('querystring')
+ , exec = require('child_process').exec
, path = require('path')
+ , dir = process.cwd()
, errors = require('./errors')
, response = require('./response')
, model = require('./model')
@@ -30,26 +32,12 @@ var fs = require('fs')
, BaseController = require('./base_controller').BaseController
, sessions = require('./sessions')
, CookieCollection = require('./cookies').CookieCollection
- , dir = process.cwd()
- , vm = require('vm')
- , exec = require('child_process').exec;
-
-// Node 0.4
-if (geddy.FD_HACK) {
- worker = require('../lib/cluster/hack_worker');
-}
-// Node 0.6
-else {
- worker = require('../lib/cluster/worker');
-}
-geddy.worker = new worker.Worker();
+ , InFlight = require('./in_flight').InFlight;
// Set up a bunch of aliases
-geddy.server = geddy.worker.server;
-geddy.config = geddy.worker.config;
-geddy.log = geddy.worker.log;
geddy.FunctionRouter = FunctionRouter;
geddy.RegExpRouter = RegExpRouter;
+geddy.inFlight = new InFlight();
geddy.inflection = inflection;
geddy.model = model;
@@ -196,7 +184,7 @@ var App = function () {
this.templateRegistry = {};
this.controllerRegistry = {};
- this.init = function () {
+ this.init = function (callback) {
var self = this
, items
, chain;
@@ -212,13 +200,13 @@ var App = function () {
chain = new geddy.async.SimpleAsyncChain(items, this);
chain.last = function () {
- self.start();
+ self.start(callback);
};
chain.run();
};
- this.start = function () {
+ this.start = function (callback) {
var self = this
, ctors = this.controllerRegistry
, router = this.router;
@@ -244,7 +232,7 @@ var App = function () {
, sessions: false
}
, finish
- , accessTime = new Date();
+ , accessTime = (new Date()).getTime();
finish = function (step) {
steps[step] = true;
@@ -253,18 +241,12 @@ var App = function () {
return false;
}
}
- controller.accessTime = accessTime.getTime();
- controller._handleAction.call(controller, params.action);
- };
- //TODO: get better logs (including http status codes)
- // by wrapping serverResponse.end()
- req.addListener('end', function () {
- geddy.log.access(req.connection.remoteAddress +
- " " + accessTime + " " + req.method + " " + req.url);
- });
+ geddy.inFlight.addEntry(req, method, resp, accessTime);
- self.requestTime = (new Date()).getTime();
+ controller.accessTime = accessTime;
+ controller._handleAction.call(controller, params.action);
+ };
if (router) {
urlParams = url.parse(req.url, true).query;
@@ -381,11 +363,9 @@ var App = function () {
}
});
- geddy.worker.start();
-
+ callback();
};
- this.init();
};
module.exports.App = App;
View
2  lib/cluster/hack_worker.js
@@ -49,7 +49,7 @@ geddy.mixin(Worker.prototype, new (function () {
});
};
- this.start = function (fd) {
+ this.startServer = function (fd) {
if (this._fd && this.config) {
this.server.listenFD(this._fd, 'tcp4');
this.log.info('Server worker running in ' + this.config.environment +
View
2  lib/cluster/worker.js
@@ -28,7 +28,7 @@ Worker.prototype = new (function () {
this.server = http.createServer();
};
- this.start = function () {
+ this.startServer = function () {
if (this.config) {
this.server.listen(parseInt(this.config.port, 10));
this.log.info('Server worker running in ' + this.config.environment +
Please sign in to comment.
Something went wrong with that request. Please try again.