Permalink
Browse files

Release v0.0.32

  • Loading branch information...
1 parent 18c0275 commit 936c636c1cd67c767aae09971b08c64c3c73f0ff @pgte committed Oct 20, 2010
Showing with 46 additions and 33 deletions.
  1. +4 −0 ChangeLog
  2. +41 −32 lib/fugue.js
  3. +1 −1 package.json
View
@@ -1,3 +1,7 @@
+2010.10.20 v0.0.32
+
+* JSLint output is cleaner now
+
2010.10.20 v0.0.31
* Kill workers if they aren't dead after 30 seconds.
View
@@ -10,28 +10,30 @@ var worker_kill_timeout;
var isMaster = exports.isMaster = function() {
return !process.env._FUGUE_WORKER;
-}
+};
var workerId = exports.workerId = function() {
- return process.env._FUGUE_WORKER !== undefined ? parseInt(process.env._FUGUE_WORKER) : null;
-}
+ return process.env._FUGUE_WORKER !== undefined ? parseInt(process.env._FUGUE_WORKER, 10) : null;
+};
var masterSocketPath = exports.masterSocketPath = function() {
return master_socket_path;
-}
+};
exports.workerPids = function() {
var worker_pids = [];
workers.forEach(function(worker) {
worker_pids.push(worker.pid);
});
return worker_pids;
-}
+};
var stop = exports.stop = function() {
if (isMaster()) {
var workers_are_all_dead = function() {
workers = [];
netBinding = process.binding('net');
- if (server_socket) netBinding.close(server_socket);
+ if (server_socket) {
+ netBinding.close(server_socket);
+ }
if (the_server) {
the_server.watcher.stop();
the_server = null;
@@ -43,7 +45,7 @@ var stop = exports.stop = function() {
if (master_socket_path) {
// try to remove the
try {
- require('fs').unlinkSync(master_socket_path)
+ require('fs').unlinkSync(master_socket_path);
} catch(excp) {
// do nothing
}
@@ -54,7 +56,7 @@ var stop = exports.stop = function() {
process.removeListener('SIGHUP', killer);
process.removeListener('SIGTERM', killer);
process.removeListener('SIGUSR2', respawner);
- }
+ };
var workers_died = 0;
@@ -88,17 +90,17 @@ var stop = exports.stop = function() {
worker.kill();
} catch(excep) {
// do nothing, just log
- console.log('Error killing worker with pid ' + worker.pid + ': ' + excep.message)
+ console.log('Error killing worker with pid ' + worker.pid + ': ' + excep.message);
}
});
}
-}
+};
exports.start = function(server, port, host, worker_count, options) {
the_server = server;
- function isPort (x) { return parseInt(x) >= 0; }
+ function isPort (x) { return parseInt(x, 10) >= 0; }
var unix_socket_path = null;
if (!isPort(port)) {
@@ -118,10 +120,12 @@ exports.start = function(server, port, host, worker_count, options) {
verbose: false,
worker_to_master_ping_interval: 30000,
worker_kill_timeout: 30000
- }
+ };
if (options) {
(function(obj1, obj2) {
- for (attrname in obj2) { obj1[attrname] = obj2[attrname]; }
+ for (var attrname in obj2) {
+ obj1[attrname] = obj2[attrname];
+ }
})(default_options, options);
}
options = default_options;
@@ -161,7 +165,6 @@ exports.start = function(server, port, host, worker_count, options) {
spawn = require('child_process').spawn,
sys = require('sys'),
fs = require('fs'),
- path = require('path'),
netBinding = process.binding('net');
// Redirect stdout and stderr
@@ -212,7 +215,7 @@ exports.start = function(server, port, host, worker_count, options) {
var length = null;
// Node returns length and sets (or not) fd by design as explained in node_net.cc / RecvMsg
do {
- length = netBinding.recvMsg(client_socket, responseBuffer, 0, responseBuffer.length)
+ length = netBinding.recvMsg(client_socket, responseBuffer, 0, responseBuffer.length);
} while(!netBinding.recvMsg.fd);
log('Got response from server:' + responseBuffer.toString('ascii', 0, length));
@@ -223,7 +226,7 @@ exports.start = function(server, port, host, worker_count, options) {
if (!server_socket) {
log('Failed to get socket from original server.');
- log('Now I\'m going to try to create one...')
+ log('Now I\'m going to try to create one...');
}
}
@@ -259,10 +262,12 @@ exports.start = function(server, port, host, worker_count, options) {
case 'GIMME_SOCKET':
log('serving server socket file descriptor ' + server_socket);
conn.write('HERE_YOU_GO', 'ascii', server_socket);
- break
+ break;
case 'LISTENING':
workers_started ++;
- if (options.started && workers_started == worker_count) options.started();
+ if (options.started && workers_started == worker_count) {
+ options.started();
+ }
break;
case 'PING':
conn.write("PONG\n");
@@ -293,21 +298,21 @@ exports.start = function(server, port, host, worker_count, options) {
spawn_worker(worker_idx);
});
- }
+ };
log('Spawning workers...');
process.env._FUGUE_WORKER_COUNT = worker_count;
for (var worker_idx = 0; worker_idx < worker_count; worker_idx ++) {
spawn_worker(worker_idx);
}
- log('spawned.')
+ log('spawned.');
killer = function() {
stop();
process.nextTick(function() {
process.exit();
});
- }
+ };
// Listen for process exits
process.on('SIGINT', killer);
@@ -319,24 +324,26 @@ exports.start = function(server, port, host, worker_count, options) {
log('Got SIGUSR2, respawning self');
// respawn self
var env = {};
- for(var i in process.env){
+ for(var i in process.env) {
env[i] = process.env[i];
}
env._FUGUE_ORIG_MASTER_PID = process.pid.toString();
var args = process.argv;
// spawn worker process
- spawned = spawn(args[0], args.slice(1), env);
+ var spawned = spawn(args[0], args.slice(1), env);
spawned.stdout.on('data', function(data) {
log("New master goes: " + data);
});
- }
+ };
process.on('SIGUSR2', respawner);
// Save master PID
if (options.master_pid_path) {
fs.writeFile(options.master_pid_path, process.pid.toString(), function(error) {
- if (error) throw new Error("Error saving master PID file in " + options.master_pid_path + ': ' + error);
+ if (error) {
+ throw new Error("Error saving master PID file in " + options.master_pid_path + ': ' + error);
+ }
});
}
@@ -353,15 +360,15 @@ exports.start = function(server, port, host, worker_count, options) {
var die_soon = false; // tells if worker should die after serving exisiting connections
// Setup killer
var worker_killer = function() {
- if(connection_count == 0) {
+ if(connection_count === 0) {
process.exit();
} else {
// Stop listening for new connections - remove watcher from the event loop
server.watcher.stop();
// Set process to die after serving existing connections
die_soon = true;
}
- }
+ };
process.on('SIGINT', worker_killer);
process.on('SIGHUP', worker_killer);
process.on('SIGTERM', worker_killer);
@@ -376,7 +383,7 @@ exports.start = function(server, port, host, worker_count, options) {
connection.flush();
connection.on('fd', function(fd) {
- var kill_master_pid = parseInt(process.env._FUGUE_ORIG_MASTER_PID);
+ var kill_master_pid = parseInt(process.env._FUGUE_ORIG_MASTER_PID, 10);
// only the last worker tries to kill original master
if (!!kill_master_pid && workerId() == process.env._FUGUE_WORKER_COUNT) {
log('killing original master');
@@ -409,8 +416,10 @@ exports.start = function(server, port, host, worker_count, options) {
ping_connection.on('connect', function() {
ping_connection.write("PING\n");
require('carrier').carry(ping_connection, function(response) {
- if(response == 'PONG') ping_connection.end();
- })
+ if(response == 'PONG') {
+ ping_connection.end();
+ }
+ });
});
ping_connection.on('error', function(error) {
if(!die_soon) {
@@ -426,11 +435,11 @@ exports.start = function(server, port, host, worker_count, options) {
connection_count ++;
connection.on('close', function() {
connection_count --;
- if (die_soon && connection_count == 0) {
+ if (die_soon && connection_count === 0) {
process.exit();
}
});
});
}
-}
+};
View
@@ -1,6 +1,6 @@
{ "name" : "fugue"
, "description" : "Unicorn for node for node"
-, "version" : "0.0.31"
+, "version" : "0.0.32"
, "homepage" : "http://www.metaduck.com/fugue"
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com> (http://www.metaduck.com)"
, "contributors" :

0 comments on commit 936c636

Please sign in to comment.