Skip to content

fix(Shard): add env, execArgv, and argv for worker-based shards #10429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
11 changes: 8 additions & 3 deletions packages/discord.js/src/sharding/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class Shard extends EventEmitter {
this.silent = manager.silent;

/**
* Arguments for the shard's process (only when {@link ShardingManager#mode} is `process`)
* Arguments for the shard's process/worker
* @type {string[]}
*/
this.args = manager.shardArgs ?? [];

/**
* Arguments for the shard's process executable (only when {@link ShardingManager#mode} is `process`)
* Arguments for the shard's process/worker executable
* @type {string[]}
*/
this.execArgv = manager.execArgv;
Expand Down Expand Up @@ -136,7 +136,12 @@ class Shard extends EventEmitter {
.on('exit', this._exitListener);
break;
case 'worker':
this.worker = new Worker(path.resolve(this.manager.file), { workerData: this.env })
this.worker = new Worker(path.resolve(this.manager.file), {
workerData: this.env,
env: this.env,
execArgv: this.execArgv,
argv: this.args,
})
.on('message', this._handleMessage.bind(this))
.on('exit', this._exitListener);
break;
Expand Down
2 changes: 0 additions & 2 deletions packages/discord.js/src/sharding/ShardingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class ShardingManager extends EventEmitter {
* @property {boolean} [silent=false] Whether to pass the silent flag to child process
* (only available when mode is set to 'process')
* @property {string[]} [shardArgs=[]] Arguments to pass to the shard script when spawning
* (only available when mode is set to 'process')
* @property {string[]} [execArgv=[]] Arguments to pass to the shard script executable when spawning
* (only available when mode is set to 'process')
* @property {string} [token] Token to use for automatic shard count and passing to shards
*/

Expand Down