Comparing version 1.2.0 to 2.0.0
@@ -7,2 +7,3 @@ var os = require('os'), | ||
Port = require('./port'), | ||
RestartQueue = require('./restart_queue'), | ||
Master; | ||
@@ -27,14 +28,7 @@ | ||
/** | ||
* Contains workers queued to restart. | ||
* @see Master#processRestartQueue | ||
* @type {WorkerWrapper[]} | ||
*/ | ||
this.restartQueue = []; | ||
/** | ||
* If `true` processing Master#restartQueue in progress. | ||
* @type {Boolean} | ||
* Workers restart queue. | ||
* @type {RestartQueue} | ||
* @private | ||
*/ | ||
this._isRestartQueued = false; | ||
this._restartQueue = new RestartQueue(); | ||
@@ -52,3 +46,2 @@ /** | ||
this.on('worker ready', this._onWorkerReady.bind(this)); | ||
this.on('worker state', this._cleanupUnixSockets.bind(this)); | ||
@@ -95,3 +88,3 @@ this.on('worker exit', this._checkWorkersAlive.bind(this)); | ||
if (this._isRestartQueued || | ||
if (this._restartQueue.has(worker) || | ||
state !== WorkerWrapper.STATES.LAUNCHING || | ||
@@ -134,17 +127,2 @@ port.family !== Port.UNIX) { | ||
/** | ||
* @param {WorkerWrapper} worker | ||
* @private | ||
*/ | ||
Master.prototype._onWorkerReady = function(worker) { | ||
// @todo what if one worker from queue die? Queue processing will be stopped... | ||
if (this._isRestartQueued && | ||
worker.wid === this.restartQueue[0].wid) { | ||
// worker on top of the queue has been restarted drop it... | ||
this.restartQueue.shift(); | ||
// ...and take the next or finish queue processing | ||
this._restartWorkerFromQueue(); | ||
} | ||
}; | ||
/** | ||
* Repeat WorkerWrapper events on Master and add 'worker ' prefix to event names | ||
@@ -340,5 +318,6 @@ * so for example 'online' became 'worker online' | ||
* Hard workers restart: all workers will be restarted at same time. | ||
* CAUTION: if dead worker is restarted, it will emit 'error' event. | ||
* @public | ||
* @returns {Master} self | ||
* @fires Master#restarted then workers spawned and ready. | ||
* @fires Master#restarted when workers spawned and ready. | ||
*/ | ||
@@ -361,38 +340,31 @@ Master.prototype.restart = function() { | ||
/** | ||
* Workers will be restarted one by one. | ||
* Workers will be restarted one by one using RestartQueue. | ||
* If a worker becomes dead, it will be just removed from restart queue. However, if already dead worker is pushed | ||
* into the queue, it will emit 'error' on restart. | ||
* @public | ||
* @returns {Master} self | ||
* @fires Master#restarted when workers spawned and ready. | ||
*/ | ||
Master.prototype.softRestart = function() { | ||
this.forEach(function(worker) { | ||
this.restartQueue.push(worker); | ||
worker.softRestart(); | ||
}); | ||
this.processRestartQueue(); | ||
this._restartQueue.once('drain', this.emit.bind(this, 'restarted')); | ||
return this; | ||
}; | ||
/** | ||
* Start processing restartQueue if it isn't started already. | ||
* @see event:Master#'worker state'('running') | ||
* Schedules one worker restart using RestartQueue. | ||
* If a worker becomes dead, it will be just removed from restart queue. However, if already dead worker is pushed | ||
* into the queue, it will emit 'error' on restart. | ||
* @public | ||
* @param {WorkerWrapper} worker | ||
* @returns {Master} self | ||
*/ | ||
Master.prototype.processRestartQueue = function() { | ||
if ( ! this._isRestartQueued) { | ||
this._isRestartQueued = true; | ||
this._restartWorkerFromQueue(); | ||
} | ||
Master.prototype.scheduleWorkerRestart = function(worker) { | ||
this._restartQueue.push(worker); | ||
return this; | ||
}; | ||
/** | ||
* Restart worker from the top of the Master#restartQueue | ||
* @private | ||
*/ | ||
Master.prototype._restartWorkerFromQueue = function() { | ||
if (this.restartQueue.length === 0) { | ||
this.emit('restarted'); | ||
this._isRestartQueued = false; | ||
} else { | ||
this.restartQueue[0].restart(); | ||
} | ||
}; | ||
/** | ||
* @override | ||
@@ -399,0 +371,0 @@ * @see ClusterProcess |
@@ -189,3 +189,3 @@ var cluster = require('cluster'), | ||
/** | ||
* Number of sequential death when worker life time was less than `exitThreshold` option value. | ||
* Number of sequential deaths when worker life time was less than `exitThreshold` option value. | ||
* @type {Number} | ||
@@ -202,5 +202,16 @@ * @private | ||
/** | ||
* Indicates whether ready() method was called in worker | ||
* @public | ||
* @type {Boolean} | ||
*/ | ||
this.ready = false; | ||
/** | ||
* @type {Master} | ||
* @private | ||
*/ | ||
this._master = master; | ||
/** | ||
* Listen for cluster#fork and worker events. | ||
@@ -642,2 +653,10 @@ * @see WorkerWrapper#_proxyEvents to know about repeating worker events on WorkerWrapper instance. | ||
/** | ||
* Adds this worker to master's restart queue | ||
* @public | ||
*/ | ||
WorkerWrapper.prototype.softRestart = function() { | ||
this._master.scheduleWorkerRestart(this); | ||
}; | ||
module.exports = WorkerWrapper; |
{ | ||
"name": "luster", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Node.js cluster wrapper", | ||
@@ -12,4 +12,4 @@ "main": "./lib/luster.js", | ||
"unit": "istanbul test _mocha -- test/unit/test", | ||
"func": "mocha test/func/test", | ||
"test": "npm run lint && npm run unit && npm run func" | ||
"func": "mocha test/func/test $@", | ||
"test": "npm run lint && npm run unit && npm run func -- $@" | ||
}, | ||
@@ -16,0 +16,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85215
19
2213