Skip to content

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Llamas committed Feb 23, 2013
1 parent dd305b6 commit 9a27155
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES
@@ -1,3 +1,6 @@
v0.1.3 (23 Feb 2013)
Fixed workers check on master.

v0.1.2 (22 Feb 2013)
Added "exit" event.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@ _Node.js project_

#### Graceful shutdown with domains and cluster support ####

Version: 0.1.2
Version: 0.1.3

Provides an event-based mechanism to start and gracefully shutdown a Node.js process when a SIGINT signal is sent to it. Because Windows doesn't have POSIX signals a different method has to be used (reading the stdin for a ctrl-c key). The process can be gracefully killed pressing ctrl-c (Windows & Linux) and sending to it a SIGINT signal (Linux). It also uses domains so uncaught exceptions doesn't kill the process. Furthermore, if you use workers, the shutdown task takes care about that and transparently manages them in order to always guarantee a graceful shutdown providing to the user a last opportunity to clean up tasks asynchronously.

Expand Down
17 changes: 10 additions & 7 deletions lib/graceful-shut.js
Expand Up @@ -80,12 +80,12 @@ util.inherits (Grace, events.EventEmitter);
Grace.prototype._masterExit = function (code){
if (cluster.isWorker) return;

var me = this;

if (this._exitCode !== undefined && this._exitCode !== null){
code = this._exitCode;
}

var me = this;

if (WIN && cluster.isMaster){
//If shutdown() is called from the master then stop reading the stdin
rl.close ();
Expand All @@ -112,6 +112,8 @@ Grace.prototype._masterExit = function (code){
Grace.prototype._workerExit = function (code){
if (cluster.isMaster) return;

var me = this;

if (this._exitCode !== undefined && this._exitCode !== null){
code = this._exitCode;
}
Expand All @@ -121,14 +123,12 @@ Grace.prototype._workerExit = function (code){
process.reallyExit (code);
});

var me = this;

if (!me._disconnectCallback){
if (!this._disconnectCallback){
//shutdown() was called directly on the worker, call to destroy()
cluster.worker.destroy ();
}else{
//Call to the original disconnect and try to gracefully shutdown
me._disconnectCallback ();
this._disconnectCallback ();
}
};

Expand Down Expand Up @@ -250,7 +250,6 @@ Grace.prototype.start = function (){

if (cluster.isMaster){
var workers = Object.keys (cluster.workers).length;
this._hasWorkers = !!workers;

if (WIN){
//On Windows if there's no more active workers the master must stop
Expand Down Expand Up @@ -284,6 +283,10 @@ Grace.prototype.shutdown = function (code){
if (this._shutdown) return;
this._shutdown = true;

if (cluster.isMaster){
this._hasWorkers = !!Object.keys (cluster.workers).length;
}

this._exitCode = code;
var me = this;

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "graceful-shut",
"version": "0.1.2",
"version": "0.1.3",
"description": "Graceful shutdown with domains and cluster support",
"keywords": ["graceful", "shutdown", "domain"],
"author": {
Expand Down

0 comments on commit 9a27155

Please sign in to comment.