cluster: add cwd to cluster.settings
This commit allows cluster workers to be created with configurable working directories. Fixes: https://github.com/nodejs/node/issues/16388 PR-URL: https://github.com/nodejs/node/pull/18399 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
0778f79cb3
commit
e0864e50ec
@ -711,6 +711,8 @@ changes:
|
|||||||
* `exec` {string} File path to worker file. **Default:** `process.argv[1]`
|
* `exec` {string} File path to worker file. **Default:** `process.argv[1]`
|
||||||
* `args` {Array} String arguments passed to worker.
|
* `args` {Array} String arguments passed to worker.
|
||||||
**Default:** `process.argv.slice(2)`
|
**Default:** `process.argv.slice(2)`
|
||||||
|
* `cwd` {string} Current working directory of the worker process. **Default:**
|
||||||
|
`undefined` (inherits from parent process)
|
||||||
* `silent` {boolean} Whether or not to send output to parent's stdio.
|
* `silent` {boolean} Whether or not to send output to parent's stdio.
|
||||||
**Default:** `false`
|
**Default:** `false`
|
||||||
* `stdio` {Array} Configures the stdio of forked processes. Because the
|
* `stdio` {Array} Configures the stdio of forked processes. Because the
|
||||||
|
@ -126,6 +126,7 @@ function createWorkerProcess(id, env) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fork(cluster.settings.exec, cluster.settings.args, {
|
return fork(cluster.settings.exec, cluster.settings.args, {
|
||||||
|
cwd: cluster.settings.cwd,
|
||||||
env: workerEnv,
|
env: workerEnv,
|
||||||
silent: cluster.settings.silent,
|
silent: cluster.settings.silent,
|
||||||
windowsHide: cluster.settings.windowsHide,
|
windowsHide: cluster.settings.windowsHide,
|
||||||
|
22
test/parallel/test-cluster-cwd.js
Normal file
22
test/parallel/test-cluster-cwd.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const cluster = require('cluster');
|
||||||
|
|
||||||
|
if (cluster.isMaster) {
|
||||||
|
common.refreshTmpDir();
|
||||||
|
|
||||||
|
assert.strictEqual(cluster.settings.cwd, undefined);
|
||||||
|
cluster.fork().on('message', common.mustCall((msg) => {
|
||||||
|
assert.strictEqual(msg, process.cwd());
|
||||||
|
}));
|
||||||
|
|
||||||
|
cluster.setupMaster({ cwd: common.tmpDir });
|
||||||
|
assert.strictEqual(cluster.settings.cwd, common.tmpDir);
|
||||||
|
cluster.fork().on('message', common.mustCall((msg) => {
|
||||||
|
assert.strictEqual(msg, common.tmpDir);
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
process.send(process.cwd());
|
||||||
|
process.disconnect();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user