remove cleanup shard logic

This commit is contained in:
Skillz4Killz
2021-05-23 20:14:15 +00:00
committed by GitHub
parent 59d35230b1
commit 4e9cbd06f5
6 changed files with 71 additions and 56 deletions

View File

@@ -174,8 +174,6 @@ export const ws = {
log,
/** Handles resharding the bot when necessary. */
resharder,
/** Cleanups loading shards that were unable to load. */
cleanupLoadingShards,
};
export interface DiscordenoShard {

View File

@@ -1,20 +0,0 @@
import { ws } from "./ws.ts";
/** The handler to clean up shards that identified but never received a READY. */
export function cleanupLoadingShards() {
if (!ws.loadingShards.size) return;
ws.log("DEBUG", "Running setTimeout in cleanupLoadingShards function.");
const now = Date.now();
ws.loadingShards.forEach((loadingShard) => {
ws.log("DEBUG", `Running forEach loop in cleanupLoadingShards function.`);
// Not a minute yet. Max should be few seconds but do a minute to be safe.
if (now < loadingShard.startedAt + 60000) return;
loadingShard.reject(
`[Identify Failure] Shard ${loadingShard.shardId} has not received READY event in over a minute.`
);
});
if (ws.loadingShards.size) setTimeout(cleanupLoadingShards, 10000);
}

View File

@@ -54,10 +54,13 @@ export function identify(shardId: number, maxShards: number) {
ws.loadingShards.set(shardId, {
shardId,
resolve,
reject,
startedAt: Date.now(),
});
ws.cleanupLoadingShards();
setTimeout(() => {
reject(
`[Identify Failure] Shard ${shardId} has not received READY event in over a minute.`
);
}, 600000);
});
}

View File

@@ -1,6 +1,5 @@
import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
import { Collection } from "../util/collection.ts";
import { cleanupLoadingShards } from "./cleanup_loading_shards.ts";
import { closeWS } from "./close_ws.ts";
import { createShard } from "./create_shard.ts";
import { log } from "./events.ts";
@@ -78,7 +77,6 @@ export const ws = {
{
shardId: number;
resolve: (value: unknown) => void;
reject: (reason?: unknown) => void;
startedAt: number;
}
>(),
@@ -112,8 +110,6 @@ export const ws = {
log,
/** Handles resharding the bot when necessary. */
resharder,
/** Cleanups loading shards that were unable to load. */
cleanupLoadingShards,
/** Handles the message events from websocket. */
handleOnMessage,
/** Handles processing queue of requests send to this shard. */