Skip to content
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
8 changes: 6 additions & 2 deletions src/instance/BotInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ export abstract class BotInstance {

private readonly execArgv: string[];

private readonly env: NodeJS.ProcessEnv;

public readonly clusters: Map<number, ClusterProcess> = new Map();

protected _shuttingDown = false;

protected constructor(entryPoint: string, execArgv?: string[]) {
protected constructor(entryPoint: string, execArgv?: string[], env?: NodeJS.ProcessEnv) {
this.entryPoint = entryPoint;
this.execArgv = execArgv ?? [];
this.env = env ?? {};
}

protected readonly eventMap: BotInstanceEventListeners = {
Expand Down Expand Up @@ -44,6 +47,7 @@ export abstract class BotInstance {
try {
const childProcess = fork(this.entryPoint, {
env: {
...this.env,
INSTANCE_ID: instanceID.toString(),
CLUSTER_ID: clusterID.toString(),
SHARD_LIST: shardList.join(','),
Expand Down Expand Up @@ -210,4 +214,4 @@ export type BotInstanceEventListeners = {
'SELF_CHECK_SUCCESS': (() => void) | undefined,
'SELF_CHECK_ERROR': ((error: string) => void) | undefined,
'SELF_CHECK_RECEIVED': ((data: { clusterList: number[] }) => void) | undefined,
};
};
6 changes: 3 additions & 3 deletions src/instance/ManagedInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class ManagedInstance extends BotInstance {

private dev: boolean = false;

constructor(entryPoint: string, host: string, port: number, instanceID: number, data: unknown, execArgv?: string[], dev?: boolean) {
super(entryPoint, execArgv);
constructor(entryPoint: string, host: string, port: number, instanceID: number, data: unknown, execArgv?: string[], env?: NodeJS.ProcessEnv, dev?: boolean) {
super(entryPoint, execArgv, env);

this.host = host;
this.port = port;
Expand Down Expand Up @@ -307,4 +307,4 @@ export class ManagedInstance extends BotInstance {
type: 'INSTANCE_STOP'
});
}
}
}
6 changes: 3 additions & 3 deletions src/instance/StandaloneInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class StandaloneInstance extends BotInstance {
public readonly token: string;
public readonly intents: GatewayIntentsString[];

constructor(entryPoint: string, shardsPerCluster: number, totalClusters: number, token: string, intents: GatewayIntentsString[], execArgv?: string[]) {
super(entryPoint, execArgv);
constructor(entryPoint: string, shardsPerCluster: number, totalClusters: number, token: string, intents: GatewayIntentsString[], execArgv?: string[], env?: NodeJS.ProcessEnv) {
super(entryPoint, execArgv, env);
this.shardsPerCluster = shardsPerCluster;
this.totalClusters = totalClusters;
this.token = token;
Expand Down Expand Up @@ -100,4 +100,4 @@ export class StandaloneInstance extends BotInstance {
return Promise.reject(new Error(`Unknown request type: ${message.type}`));
}

}
}
1 change: 1 addition & 0 deletions test/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const machine = new ManagedInstance(
key: "value",
},
["--import", "tsx"],
process.env,
false,
);

Expand Down