From 9a27155b38c070296c47c2f8c1a142a02306a233 Mon Sep 17 00:00:00 2001 From: Gabriel Llamas Date: Sat, 23 Feb 2013 11:45:21 +0100 Subject: [PATCH] v0.1.3 --- CHANGES | 3 +++ README.md | 2 +- lib/graceful-shut.js | 17 ++++++++++------- package.json | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 2069ced..b256ea5 100644 --- a/CHANGES +++ b/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. diff --git a/README.md b/README.md index e896cb6..ba230a2 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/graceful-shut.js b/lib/graceful-shut.js index 50408e8..9e2259e 100644 --- a/lib/graceful-shut.js +++ b/lib/graceful-shut.js @@ -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 (); @@ -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; } @@ -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 (); } }; @@ -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 @@ -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; diff --git a/package.json b/package.json index 51436f6..4c65c4c 100644 --- a/package.json +++ b/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": {