Skip to content

Commit

Permalink
Fix kill issues
Browse files Browse the repository at this point in the history
  • Loading branch information
meister03 committed Dec 27, 2022
1 parent 7cb1a7f commit a3a9226
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 53 deletions.
2 changes: 1 addition & 1 deletion dist/Core/Cluster.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 9 additions & 13 deletions dist/Core/Cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Cluster extends events_1.default {
this.thread?.kill();
this.manager.heartbeat?.clusters.get(this.id)?.stop();
this.restarts.cleanup();
this._handleExit(false, options);
this.manager._debug('[KILL] Cluster killed with reason: ' + (options?.reason || 'not given'), this.id);
}
/**
* Kills and restarts the cluster's process/worker.
Expand Down Expand Up @@ -264,23 +264,19 @@ class Cluster extends events_1.default {
* @param {handleExitOptions} options
* @private
*/
_handleExit(respawn = this.manager.respawn, options) {
_handleExit(exitCode) {
/**
* Emitted upon the cluster's child process/worker exiting.
* @event Cluster#death
* @param {Child|Worker} process Child process/worker that exited
*/
if (!options)
options = {};
if (options?.reason !== 'reclustering')
this.emit('death', this, this.thread?.process);
if (respawn) {
this.manager._debug('[DEATH] Cluster died, attempting respawn | Restarts Left: ' +
(this.restarts.max - this.restarts.current), this.id);
}
else {
this.manager._debug('[KILL] Cluster killed with reason: ' + (options?.reason || 'not given'), this.id);
}
const respawn = this.manager.respawn;
// Cleanup functions
this.manager.heartbeat?.clusters.get(this.id)?.stop();
this.restarts.cleanup();
this.emit('death', this, this.thread?.process);
this.manager._debug('[DEATH] Cluster died, attempting respawn | Restarts Left: ' +
(this.restarts.max - this.restarts.current), this.id);
this.ready = false;
this.thread = null;
if (!respawn)
Expand Down
2 changes: 1 addition & 1 deletion dist/Core/ClusterManager.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/Core/ClusterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class ClusterManager extends events_1.default {
/**
* Spawns multiple internal shards.
*/
async spawn({ amount = this.totalShards, delay, timeout } = this.spawnOptions) {
async spawn({ amount = this.totalShards, delay, timeout = 30000 } = this.spawnOptions) {
if (delay < 7000) {
process.emitWarning(`Spawn Delay (delay: ${delay}) is smaller than 7s, this can cause global rate limits on /gateway/bot`, {
code: 'CLUSTER_MANAGER',
Expand Down
3 changes: 0 additions & 3 deletions dist/types/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ export interface ClusterKillOptions {
reason?: string;
force: boolean;
}
export interface handleExitOptions {
reason?: string;
}
export interface Plugin {
build(manager: ClusterManager): void;
}
Expand Down
Loading

0 comments on commit a3a9226

Please sign in to comment.