Skip to content

Commit

Permalink
fix: listening message dispatched before workers are ready (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba committed Apr 18, 2016
1 parent 5a734e7 commit c073253
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/social-network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"lux-framework": "0.0.1-beta.1",
"lux-framework": "0.0.1-beta.2",
"babel-core": "6.7.4",
"babel-eslint": "6.0.2",
"babel-plugin-transform-decorators-legacy": "1.3.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"lux-framework": "0.0.1-beta.1",
"lux-framework": "0.0.1-beta.2",
"babel-core": "6.7.4",
"babel-eslint": "6.0.2",
"babel-plugin-transform-decorators-legacy": "1.3.4",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lux-framework",
"version": "0.0.1-beta.1",
"version": "0.0.1-beta.2",
"description": "A MVC style Node.js framework for building lightning fast JSON APIs",
"repository": "https://github.com/postlight/lux",
"main": "dist/index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/packages/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Application extends Base {
}

async boot() {
const { root, router, domain } = this;
const { root, router, domain, server, port } = this;
const store = Database.create(
require(`${root}/config/database.json`)
);
Expand Down Expand Up @@ -133,7 +133,8 @@ class Application extends Base {

routes.get('routes').call(null, router.route, router.resource);

this.server.listen(this.port);
server.instance.once('listening', () => process.send('ready'));
server.listen(port);

return this;
}
Expand Down
18 changes: 12 additions & 6 deletions src/packages/cli/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ export default async function serve(port = 4000) {
const Application = require(`${pwd}/bin/app`);
const config = require(`${pwd}/config/environments/${env}.json`);
const logger = await Logger.create();
let workers = 0;

if (config.port) {
port = config.port;
}

if (cluster.isMaster) {
for (var i = 0; i < os.cpus().length; i++) {
cluster.fork().once('online', () => {
workers++;
if (i === workers) {
logger.log(`Lux Server listening on port ${cyan(`${port}`)}`);
const total = os.cpus().length;
let current = 0;

logger.log(`Starting Lux Server with ${cyan(`${total}`)} worker processes`);

for (let i = 0; i < total; i++) {
cluster.fork().once('message', msg => {
if (msg === 'ready') {
current++;
if (current === total) {
logger.log(`Lux Server listening on port ${cyan(`${port}`)}`);
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import generate from './commands/generate';

import tryCatch from '../../utils/try-catch';

cli.version('0.0.1-beta.1');
cli.version('0.0.1-beta.2');

cli
.command('n <name>')
Expand Down
2 changes: 1 addition & 1 deletion src/packages/cli/templates/package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default (name) => {
"author": "",
"license": "MIT",
"dependencies": {
"lux-framework": "0.0.1-beta.1",
"lux-framework": "0.0.1-beta.2",
"babel-core": "6.7.4",
"babel-eslint": "6.0.2",
"babel-plugin-transform-decorators-legacy": "1.3.4",
Expand Down

0 comments on commit c073253

Please sign in to comment.