mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
feat(ShardingManager): add execArgv option (#2585)
This commit is contained in:
@@ -14,9 +14,8 @@ class Shard extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* @param {ShardingManager} manager Manager that is spawning this shard
|
* @param {ShardingManager} manager Manager that is spawning this shard
|
||||||
* @param {number} id ID of this shard
|
* @param {number} id ID of this shard
|
||||||
* @param {string[]} [args=[]] Command line arguments to pass to the script
|
|
||||||
*/
|
*/
|
||||||
constructor(manager, id, args = []) {
|
constructor(manager, id) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +34,13 @@ class Shard extends EventEmitter {
|
|||||||
* Arguments for the shard's process
|
* Arguments for the shard's process
|
||||||
* @type {string[]}
|
* @type {string[]}
|
||||||
*/
|
*/
|
||||||
this.args = args;
|
this.args = manager.args;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arguments for the shard's process executable
|
||||||
|
* @type {string[]}
|
||||||
|
*/
|
||||||
|
this.execArgv = manager.execArgv;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Environment variables for the shard's process
|
* Environment variables for the shard's process
|
||||||
@@ -91,7 +96,9 @@ class Shard extends EventEmitter {
|
|||||||
async spawn(waitForReady = true) {
|
async spawn(waitForReady = true) {
|
||||||
if (this.process) throw new Error('SHARDING_PROCESS_EXISTS', this.id);
|
if (this.process) throw new Error('SHARDING_PROCESS_EXISTS', this.id);
|
||||||
|
|
||||||
this.process = childProcess.fork(path.resolve(this.manager.file), this.args, { env: this.env })
|
this.process = childProcess.fork(path.resolve(this.manager.file), this.args, {
|
||||||
|
env: this.env, execArgv: this.execArgv,
|
||||||
|
})
|
||||||
.on('message', this._handleMessage.bind(this))
|
.on('message', this._handleMessage.bind(this))
|
||||||
.on('exit', this._exitListener);
|
.on('exit', this._exitListener);
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class ShardingManager extends EventEmitter {
|
|||||||
* @param {number|string} [options.totalShards='auto'] Number of shards to spawn, or "auto"
|
* @param {number|string} [options.totalShards='auto'] Number of shards to spawn, or "auto"
|
||||||
* @param {boolean} [options.respawn=true] Whether shards should automatically respawn upon exiting
|
* @param {boolean} [options.respawn=true] Whether shards should automatically respawn upon exiting
|
||||||
* @param {string[]} [options.shardArgs=[]] Arguments to pass to the shard script when spawning
|
* @param {string[]} [options.shardArgs=[]] Arguments to pass to the shard script when spawning
|
||||||
|
* @param {string[]} [options.execArgv=[]] Arguments to pass to the shard script executable when spawning
|
||||||
* @param {string} [options.token] Token to use for automatic shard count and passing to shards
|
* @param {string} [options.token] Token to use for automatic shard count and passing to shards
|
||||||
*/
|
*/
|
||||||
constructor(file, options = {}) {
|
constructor(file, options = {}) {
|
||||||
@@ -30,6 +31,7 @@ class ShardingManager extends EventEmitter {
|
|||||||
totalShards: 'auto',
|
totalShards: 'auto',
|
||||||
respawn: true,
|
respawn: true,
|
||||||
shardArgs: [],
|
shardArgs: [],
|
||||||
|
execArgv: [],
|
||||||
token: null,
|
token: null,
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
@@ -70,6 +72,12 @@ class ShardingManager extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
this.shardArgs = options.shardArgs;
|
this.shardArgs = options.shardArgs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of arguments to pass to the executable
|
||||||
|
* @type {string[]}
|
||||||
|
*/
|
||||||
|
this.execArgv = options.execArgv;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Token to use for obtaining the automatic shard count, and passing to shards
|
* Token to use for obtaining the automatic shard count, and passing to shards
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
@@ -90,7 +98,7 @@ class ShardingManager extends EventEmitter {
|
|||||||
* @returns {Shard}
|
* @returns {Shard}
|
||||||
*/
|
*/
|
||||||
createShard(id = this.shards.size) {
|
createShard(id = this.shards.size) {
|
||||||
const shard = new Shard(this, id, this.shardArgs);
|
const shard = new Shard(this, id);
|
||||||
this.shards.set(id, shard);
|
this.shards.set(id, shard);
|
||||||
/**
|
/**
|
||||||
* Emitted upon creating a shard.
|
* Emitted upon creating a shard.
|
||||||
|
|||||||
Reference in New Issue
Block a user