Skip to content
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

Add process args #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion src/cluster/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ClusterProcessOptions {
shardCount: number,
shardEnd: number,
shardStart: number,
execArgv: string[],
}

export interface ClusterProcessRunOptions {
Expand All @@ -32,6 +33,7 @@ export class ClusterProcess extends EventSpewer {
readonly _shardsWaiting = new BaseCollection<number, {resolve: Function, reject: Function}>();
readonly clusterId: number = -1;
readonly manager: ClusterManager;
readonly execArgv: string[];

env: Record<string, string | undefined> = {};
process: ChildProcess | null = null;
Expand All @@ -43,6 +45,7 @@ export class ClusterProcess extends EventSpewer {
super();
this.manager = manager;
this.clusterId = options.clusterId;
this.execArgv = options.execArgv;

Object.assign(this.env, process.env, options.env, {
CLUSTER_COUNT: String(this.manager.clusterCount),
Expand Down Expand Up @@ -296,7 +299,7 @@ export class ClusterProcess extends EventSpewer {
if (this.process) {
return this.process;
}
const process = fork(this.file, [], {env: this.env});
const process = fork(this.file, [], {env: this.env, execArgv: this.execArgv });
this.process = process;
this.process.on('message', this.onMessage.bind(this));
this.process.on('exit', this.onExit.bind(this));
Expand Down
5 changes: 4 additions & 1 deletion src/clustermanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ClusterManagerOptions {
shardCount?: number,
shards?: [number, number],
shardsPerCluster?: number,
execArgv?: string[]
}

export interface ClusterManagerRunOptions {
Expand Down Expand Up @@ -46,6 +47,7 @@ export class ClusterManager extends EventSpewer {
shardStart: number = 0;
shardsPerCluster: number = 4;
token: string;
execArgv: string[]

constructor(
file: string,
Expand All @@ -63,7 +65,7 @@ export class ClusterManager extends EventSpewer {
throw new Error('Token is required for this library to work.');
}
this.token = token;

this.execArgv = Array.isArray(options.execArgv) ? options.execArgv : process.execArgv;
this.maxConcurrency = options.maxConcurrency || this.maxConcurrency;
this.respawn = (options.respawn || options.respawn === undefined);
this.rest = new DetritusRestClient(token, {authType: AuthTypes.BOT});
Expand Down Expand Up @@ -144,6 +146,7 @@ export class ClusterManager extends EventSpewer {
shardCount,
shardEnd,
shardStart,
execArgv: this.execArgv
});
this.processes.set(clusterId, clusterProcess);
this.emit(ClientEvents.CLUSTER_PROCESS, {clusterProcess});
Expand Down