Comparing version 1.0.0 to 1.1.0
@@ -5,4 +5,6 @@ var cluster = require('cluster'), | ||
RPCCallback = require('./rpc-callback'), | ||
Configurable = require('./configurable'), | ||
Configuration = require('./configuration'), | ||
EventEmitterEx = require('./event_emitter_ex'), | ||
LusterClusterProcessError = require('./errors').LusterClusterProcessError, | ||
LusterConfigurationError = require('./errors').LusterConfigurationError, | ||
ClusterProcess; | ||
@@ -27,5 +29,5 @@ | ||
* @class ClusterProcess | ||
* @augments Configurable | ||
* @augments EventEmitterEx | ||
*/ | ||
ClusterProcess = Configurable.create(function ClusterProcess() { | ||
ClusterProcess = EventEmitterEx.create(function ClusterProcess() { | ||
ClusterProcess.__super.apply(this, arguments); | ||
@@ -40,2 +42,8 @@ | ||
/** | ||
* @type {Configuration} | ||
* @public | ||
*/ | ||
this.config = null; | ||
this.once('configured', this._onConfigured.bind(this)); | ||
@@ -71,2 +79,41 @@ | ||
/** | ||
* @event ClusterProcess#configured | ||
*/ | ||
/** | ||
* @fires ClusterProcess#configured | ||
* @param {Object} config | ||
* @param {Boolean} [applyEnv=true] | ||
* @param {String} [basedir=process.cwd()] for Configuration#resolve relative paths | ||
* @returns {ClusterProcess} this | ||
* @throws {LusterConfigurationError} if configuration check failed (check errors will be logged to STDERR) | ||
* @public | ||
*/ | ||
ClusterProcess.prototype.configure = function(config, applyEnv, basedir) { | ||
if (typeof applyEnv === 'undefined' || applyEnv) { | ||
Configuration.applyEnvironment(config); | ||
} | ||
if (typeof(basedir) === 'undefined') { | ||
basedir = process.cwd(); | ||
} | ||
if (Configuration.check(config) > 0) { | ||
this.emit('error', | ||
LusterConfigurationError.createError( | ||
LusterConfigurationError.CODES.CONFIGURATION_CHECK_FAILED)); | ||
} else { | ||
this.config = Configuration.extend(config, basedir); | ||
// hack to tweak underlying EventEmitter max listeners | ||
// if your luster-based app extensively use luster events | ||
this.setMaxListeners(this.config.get('maxEventListeners', 100)); | ||
this.emit('configured'); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* @param {String} name | ||
@@ -85,3 +132,3 @@ * @param {Function} callback function(error) | ||
// else returns original value | ||
config = this.extendConfig(config); | ||
config = Configuration.extend(config, this.config.getBaseDir()); | ||
@@ -131,3 +178,3 @@ if (extension.configure.length > 2) { | ||
ClusterProcess.prototype._onConfigured = function() { | ||
cluster.setMaxListeners(this._maxListeners); | ||
cluster.setMaxListeners(this.getMaxListeners()); | ||
@@ -134,0 +181,0 @@ // try to use `extensionsPath` option to resolve extensions' modules |
@@ -20,3 +20,2 @@ var Objex = require('objex'), | ||
EventEmitterEx.prototype.emit = function() { | ||
var iid = this.wid || this.id; | ||
var args = Array.prototype | ||
@@ -26,6 +25,4 @@ .slice.call(arguments, 0) | ||
iid = typeof iid === 'undefined' ? '' : '(' + iid + ')'; | ||
console.log('%s(%s).emit(%s)', this.constructor.name || 'EventEmitterEx', this.wid, args.join(', ')); | ||
console.log('%s%s.emit(%s)', this.constructor.name || 'EventEmitterEx', iid, args.join(', ')); | ||
return EventEmitterEx.__super.prototype.emit.apply(this, arguments); | ||
@@ -32,0 +29,0 @@ }; |
@@ -241,3 +241,3 @@ var os = require('os'), | ||
port: isServerPortSet ? port.next(group) : 0, | ||
_maxListeners: this._maxListeners | ||
maxListeners: this.getMaxListeners(), | ||
})); | ||
@@ -244,0 +244,0 @@ |
@@ -55,5 +55,5 @@ var cluster = require('cluster'), | ||
if (options && | ||
typeof options._maxListeners !== 'undefined' && | ||
options._maxListeners > this._maxListeners) { | ||
this.setMaxListeners(options._maxListeners); | ||
typeof options.maxListeners !== 'undefined' && | ||
options.maxListeners > this.getMaxListeners()) { | ||
this.setMaxListeners(options.maxListeners); | ||
} | ||
@@ -215,3 +215,6 @@ | ||
if ( ! master.hasRegisteredRemoteCommand(RPC.fns.master.broadcastWorkerEvent)) { | ||
master.registerRemoteCommand(RPC.fns.master.broadcastWorkerEvent, WorkerWrapper.broadcastWorkerEvent.bind(master)); | ||
master.registerRemoteCommand( | ||
RPC.fns.master.broadcastWorkerEvent, | ||
WorkerWrapper.broadcastWorkerEvent.bind(master) | ||
); | ||
} | ||
@@ -306,3 +309,2 @@ | ||
this.remoteCall(RPC.fns.worker.applyForeignProperties, { | ||
wid: this.wid, | ||
pid: this.process.pid | ||
@@ -479,3 +481,4 @@ }); | ||
self._worker = cluster.fork({ | ||
port: self.options.port | ||
port: self.options.port, | ||
LUSTER_WID: self.wid, | ||
}); | ||
@@ -482,0 +485,0 @@ |
@@ -17,2 +17,13 @@ var cluster = require('cluster'), | ||
/** | ||
* @memberOf {Worker} | ||
* @property {Number} Persistent Worker identifier | ||
* @readonly | ||
* @public | ||
*/ | ||
Object.defineProperty(this, 'wid', { | ||
value: process.env.LUSTER_WID, | ||
enumerable: true | ||
}); | ||
/** | ||
* Worker id (alias for cluster.worker.id) | ||
@@ -19,0 +30,0 @@ * @memberOf {Worker} |
{ | ||
"name": "luster", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Node.js cluster wrapper", | ||
@@ -5,0 +5,0 @@ "main": "./lib/luster.js", |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
82041
19
2139
10
1