Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b68e66c
Add separate worker pools
mcheshkov Jun 13, 2018
c65eaa8
Add workerEnv option
mcheshkov Jun 27, 2018
17b1d8f
Add raw getter to Configuration
mcheshkov Jun 28, 2018
9493190
Emit 'create pool' event from master to help debugging
mcheshkov Jun 28, 2018
7ac6eb9
Refactor id logging in EventEmitterEx to log eexKey
mcheshkov Jun 28, 2018
59167a1
Add WorkerPool.onceFirstRunning to ease sync
mcheshkov Jun 28, 2018
4c36f8c
Wrap require in Worker with try-catch
mcheshkov Jun 28, 2018
d41a957
Enable object spread in eslintrc
mcheshkov Jul 17, 2018
45c439d
Add extend method to Configuration instance
mcheshkov Jul 17, 2018
2d0f8be
Refactor LusterInstance helper using delay and p-event
mcheshkov Jul 18, 2018
100208c
Refactor WorkerPool.softRestart using p-event
mcheshkov Jul 18, 2018
2a02f11
Add double shutdown test
mcheshkov Jul 18, 2018
a2f24ee
Allow paaing Configuration instance to WorkerPool.configure
mcheshkov Jul 18, 2018
b2622b6
Use p-event in ClusterProcess, WorkerPool and Worker
mcheshkov Jul 18, 2018
a8a1054
Add chai-as-promised, fix unhandled rejection in ClusterProcess unit …
mcheshkov Jul 18, 2018
7fcedb5
Release 3.0.0-alpha.0
mcheshkov Jul 25, 2018
d0d6c92
Fix emitToAll not emitting from Master, make emitToAll test check this
mcheshkov Aug 3, 2018
5394d26
Release 3.0.0-alpha.1
mcheshkov Aug 3, 2018
5049bea
feature: ability to cleanup pools & workers
Jan 17, 2019
41131ec
Config path is next argument after luster filename
kvmamich Aug 10, 2018
15c29f8
Merge pull request #73 from nodules/feature/ability-to-cleanup-pools-…
kolesnikovde Feb 12, 2019
9fa9b16
3.0.0-alpha.3
Feb 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2017,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
}
}
7 changes: 5 additions & 2 deletions bin/luster.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env node
const /** @type {ClusterProcess} */
luster = require('../lib/luster'),
path = require('path'),
configFilePath = path.resolve(process.cwd(), process.argv[2] || 'luster.conf');
path = require('path');

// config path is right after this script in process.argv
const scriptArgvIndex = process.argv.findIndex(arg => arg === __filename || path.resolve(arg) === __filename);
const configFilePath = path.resolve(process.cwd(), process.argv[scriptArgvIndex + 1] || 'luster.conf');

luster.configure(require(configFilePath), true, path.dirname(configFilePath)).run();
19 changes: 12 additions & 7 deletions lib/cluster_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const cluster = require('cluster'),
LusterClusterProcessError = require('./errors').LusterClusterProcessError,
LusterConfigurationError = require('./errors').LusterConfigurationError;

const pEvent = require('p-event');

/**
* @param {Object} context
* @param {String} propName
Expand Down Expand Up @@ -59,9 +61,7 @@ class ClusterProcess extends EventEmitterEx {
* @type Promise<void>
* @private
* */
this._initPromise = new Promise(resolve => {
this.once('initialized', resolve);
});
this._initPromise = pEvent(this, 'initialized');

/**
* @type {Configuration}
Expand Down Expand Up @@ -110,6 +110,15 @@ class ClusterProcess extends EventEmitterEx {
* @public
*/
configure(config, applyEnv, basedir) {
this._setConfig(config, applyEnv, basedir);
if (this.config) {
this.emit('configured');
}

return this;
}

_setConfig(config, applyEnv, basedir) {
if (typeof applyEnv === 'undefined' || applyEnv) {
Configuration.applyEnvironment(config);
}
Expand All @@ -128,11 +137,7 @@ class ClusterProcess extends EventEmitterEx {
// 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;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions lib/configuration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Configuration {
Object.assign(this._rawConfig, config);
}

get raw() {
return this._rawConfig;
}

/**
* @param {String} path
* @param {*} [defaultValue]
Expand Down Expand Up @@ -93,6 +97,16 @@ class Configuration {
config;
}

extend(config) {
return new Configuration(
{
...this.raw,
...config,
},
this._resolveBaseDir,
);
}

/**
* Override config properties using `LUSTER_CONF` environment variable.
*
Expand Down
22 changes: 22 additions & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,26 @@ errors.LusterPortError = LusterError.create('LusterPortError',
'Can not unlink unix socket "%socketPath%"'
});

/**
* @constructor
* @class LusterMasterError
* @augments LusterError
*/
errors.LusterMasterError = LusterError.create('LusterMasterError',
{
POOL_KEY_ALREADY_TAKEN:
'Pool key "%key%" is already taken'
});

/**
* @constructor
* @class LusterMasterError
* @augments LusterError
*/
errors.LusterMasterError = LusterError.create('LusterMasterError',
{
POOL_DOES_NOT_EXIST:
'Pool with key "%key%" does not exist'
});

module.exports = errors;
4 changes: 3 additions & 1 deletion lib/event_emitter_ex.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ if (process.env.NODE_DEBUG && /luster:eex/i.test(process.env.NODE_DEBUG)) {
EventEmitterEx.prototype.emit = function(...args) {
const inspectedArgs = args.map(inspect).join(', ');

console.log('%s(%s).emit(%s)', this.constructor.name || 'EventEmitterEx', this.wid, inspectedArgs);
const key = this.eexKey;

console.log('%s(%s).emit(%s)', this.constructor.name || 'EventEmitterEx', key, inspectedArgs);

return EventEmitter.prototype.emit.apply(this, args);
};
Expand Down
Loading