Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A bit more cleanup to the startup.
  • 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
, parseopts = require('../lib/parseopts')
, utils = require('../lib/utils/index')
, App = require('../lib/app.js').App
, parser
, args = process.argv.slice(2)
, optsReg
Expand Down Expand Up @@ -71,7 +72,8 @@ var start = function () {
, master
, worker
, m
, w;
, w
, app;

// Node 0.6
try {
Expand All @@ -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);
}

Expand Down
46 changes: 13 additions & 33 deletions lib/app.js
Expand Up @@ -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')
Expand All @@ -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;

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

this.init = function () {
this.init = function (callback) {
var self = this
, items
, chain;
Expand All @@ -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;
Expand All @@ -244,7 +232,7 @@ var App = function () {
, sessions: false
}
, finish
, accessTime = new Date();
, accessTime = (new Date()).getTime();

finish = function (step) {
steps[step] = true;
Expand All @@ -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;
Expand Down Expand Up @@ -381,11 +363,9 @@ var App = function () {
}
});

geddy.worker.start();

callback();
};

this.init();
};

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) {
this.server.listenFD(this._fd, 'tcp4');
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.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 +
Expand Down

0 comments on commit 45d9276

Please sign in to comment.