Skip to content

Commit

Permalink
A bit more cleanup to the startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Dec 1, 2011
1 parent de944ab commit 45d9276
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 38 deletions.
12 changes: 9 additions & 3 deletions bin/cli.js
Expand Up @@ -7,6 +7,7 @@ var fs = require('fs')
, exec = require('child_process').exec , exec = require('child_process').exec
, parseopts = require('../lib/parseopts') , parseopts = require('../lib/parseopts')
, utils = require('../lib/utils/index') , utils = require('../lib/utils/index')
, App = require('../lib/app.js').App
, parser , parser
, args = process.argv.slice(2) , args = process.argv.slice(2)
, optsReg , optsReg
Expand Down Expand Up @@ -71,7 +72,8 @@ var start = function () {
, master , master
, worker , worker
, m , m
, w; , w
, app;


// Node 0.6 // Node 0.6
try { try {
Expand All @@ -95,8 +97,12 @@ var start = function () {
} }
// Worker-process -- start up an app // Worker-process -- start up an app
else { else {
var App = require('../lib/app.js').App; w = new worker.Worker();
var app = new App(); geddy.mixin(geddy, w);
app = new App();
app.init(function () {
w.startServer();
});
geddy.mixin(geddy, app); geddy.mixin(geddy, app);
} }


Expand Down
46 changes: 13 additions & 33 deletions lib/app.js
Expand Up @@ -19,7 +19,9 @@
var fs = require('fs') var fs = require('fs')
, url = require('url') , url = require('url')
, querystring = require('querystring') , querystring = require('querystring')
, exec = require('child_process').exec
, path = require('path') , path = require('path')
, dir = process.cwd()
, errors = require('./errors') , errors = require('./errors')
, response = require('./response') , response = require('./response')
, model = require('./model') , model = require('./model')
Expand All @@ -30,26 +32,12 @@ var fs = require('fs')
, BaseController = require('./base_controller').BaseController , BaseController = require('./base_controller').BaseController
, sessions = require('./sessions') , sessions = require('./sessions')
, CookieCollection = require('./cookies').CookieCollection , CookieCollection = require('./cookies').CookieCollection
, dir = process.cwd() , InFlight = require('./in_flight').InFlight;
, 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();


// Set up a bunch of aliases // 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.FunctionRouter = FunctionRouter;
geddy.RegExpRouter = RegExpRouter; geddy.RegExpRouter = RegExpRouter;
geddy.inFlight = new InFlight();
geddy.inflection = inflection; geddy.inflection = inflection;
geddy.model = model; geddy.model = model;


Expand Down Expand Up @@ -196,7 +184,7 @@ var App = function () {
this.templateRegistry = {}; this.templateRegistry = {};
this.controllerRegistry = {}; this.controllerRegistry = {};


this.init = function () { this.init = function (callback) {
var self = this var self = this
, items , items
, chain; , chain;
Expand All @@ -212,13 +200,13 @@ var App = function () {


chain = new geddy.async.SimpleAsyncChain(items, this); chain = new geddy.async.SimpleAsyncChain(items, this);
chain.last = function () { chain.last = function () {
self.start(); self.start(callback);
}; };


chain.run(); chain.run();
}; };


this.start = function () { this.start = function (callback) {
var self = this var self = this
, ctors = this.controllerRegistry , ctors = this.controllerRegistry
, router = this.router; , router = this.router;
Expand All @@ -244,7 +232,7 @@ var App = function () {
, sessions: false , sessions: false
} }
, finish , finish
, accessTime = new Date(); , accessTime = (new Date()).getTime();


finish = function (step) { finish = function (step) {
steps[step] = true; steps[step] = true;
Expand All @@ -253,18 +241,12 @@ var App = function () {
return false; return false;
} }
} }
controller.accessTime = accessTime.getTime();
controller._handleAction.call(controller, params.action);
};


//TODO: get better logs (including http status codes) geddy.inFlight.addEntry(req, method, resp, accessTime);
// by wrapping serverResponse.end()
req.addListener('end', function () {
geddy.log.access(req.connection.remoteAddress +
" " + accessTime + " " + req.method + " " + req.url);
});


self.requestTime = (new Date()).getTime(); controller.accessTime = accessTime;
controller._handleAction.call(controller, params.action);
};


if (router) { if (router) {
urlParams = url.parse(req.url, true).query; urlParams = url.parse(req.url, true).query;
Expand Down Expand Up @@ -381,11 +363,9 @@ var App = function () {
} }
}); });


geddy.worker.start(); callback();

}; };


this.init();
}; };


module.exports.App = App; module.exports.App = App;
Expand Down
2 changes: 1 addition & 1 deletion lib/cluster/hack_worker.js
Expand Up @@ -49,7 +49,7 @@ geddy.mixin(Worker.prototype, new (function () {
}); });
}; };


this.start = function (fd) { this.startServer = function (fd) {
if (this._fd && this.config) { if (this._fd && this.config) {
this.server.listenFD(this._fd, 'tcp4'); this.server.listenFD(this._fd, 'tcp4');
this.log.info('Server worker running in ' + this.config.environment + this.log.info('Server worker running in ' + this.config.environment +
Expand Down
2 changes: 1 addition & 1 deletion lib/cluster/worker.js
Expand Up @@ -28,7 +28,7 @@ Worker.prototype = new (function () {
this.server = http.createServer(); this.server = http.createServer();
}; };


this.start = function () { this.startServer = function () {
if (this.config) { if (this.config) {
this.server.listen(parseInt(this.config.port, 10)); this.server.listen(parseInt(this.config.port, 10));
this.log.info('Server worker running in ' + this.config.environment + this.log.info('Server worker running in ' + this.config.environment +
Expand Down

0 comments on commit 45d9276

Please sign in to comment.