mirror of https://github.com/xwiki-labs/cryptpad
interpret maxWorkers config in lib/env instead of in worker handler
This commit is contained in:
parent
bd82e86228
commit
c762353cad
10
lib/env.js
10
lib/env.js
|
@ -205,7 +205,7 @@ module.exports.create = function (config) {
|
|||
// but it is referenced in Quota
|
||||
domain: config.domain,
|
||||
|
||||
maxWorkers: config.maxWorkers,
|
||||
maxWorkers: undefined,
|
||||
disableIntegratedTasks: config.disableIntegratedTasks || false,
|
||||
disableIntegratedEviction: typeof(config.disableIntegratedEviction) === 'undefined'? true: config.disableIntegratedEviction,
|
||||
lastEviction: +new Date(),
|
||||
|
@ -213,6 +213,14 @@ module.exports.create = function (config) {
|
|||
commandTimers: {},
|
||||
};
|
||||
|
||||
(function () {
|
||||
var max = config.maxWorkers;
|
||||
// if the supplied value is not a positive number, leave maxWorkers undefined
|
||||
// one worker will be created for each CPU core
|
||||
if (typeof(max) !== 'number' || isNaN(max) || max < 1) { return; }
|
||||
Env.maxWorkers = max;
|
||||
}());
|
||||
|
||||
(function () {
|
||||
// mode can be FRESH (default), DEV, or PACKAGE
|
||||
if (process.env.PACKAGE) {
|
||||
|
|
|
@ -260,22 +260,7 @@ Workers.initialize = function (Env, config, _cb) {
|
|||
};
|
||||
|
||||
nThen(function (w) {
|
||||
const max = config.maxWorkers;
|
||||
|
||||
var limit;
|
||||
if (typeof(max) !== 'undefined') {
|
||||
// the admin provided a limit on the number of workers
|
||||
if (typeof(max) === 'number' && !isNaN(max)) {
|
||||
if (max < 1) {
|
||||
Log.info("INSUFFICIENT_MAX_WORKERS", max);
|
||||
limit = 1;
|
||||
}
|
||||
limit = max;
|
||||
} else {
|
||||
Log.error("INVALID_MAX_WORKERS", '[' + max + ']');
|
||||
}
|
||||
}
|
||||
|
||||
var limit = Env.maxWorkers;
|
||||
var logged;
|
||||
|
||||
OS.cpus().forEach(function (cpu, index) {
|
||||
|
|
Loading…
Reference in New Issue