mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 00:10:07 +00:00
startup ~5s now
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
import { delay } from "../util/utils.ts";
|
||||
import { ws } from "./ws.ts";
|
||||
|
||||
/** The handler to clean up shards that identified but never received a READY. */
|
||||
export async function cleanupLoadingShards() {
|
||||
while (ws.loadingShards.size) {
|
||||
ws.log("DEBUG", "Running while loop 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;
|
||||
export function cleanupLoadingShards() {
|
||||
if (!ws.loadingShards.size) return;
|
||||
|
||||
loadingShard.reject(
|
||||
`[Identify Failure] Shard ${loadingShard.shardId} has not received READY event in over a minute.`
|
||||
);
|
||||
});
|
||||
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;
|
||||
|
||||
await delay(1000);
|
||||
}
|
||||
loadingShard.reject(
|
||||
`[Identify Failure] Shard ${loadingShard.shardId} has not received READY event in over a minute.`
|
||||
);
|
||||
});
|
||||
|
||||
if (ws.loadingShards.size) setTimeout(cleanupLoadingShards, 10000);
|
||||
}
|
||||
|
||||
@@ -95,11 +95,11 @@ export async function handleOnMessage(message: any, shardId: number) {
|
||||
|
||||
ws.loadingShards.get(shardId)?.resolve(true);
|
||||
ws.loadingShards.delete(shardId);
|
||||
// Wait 5 seconds to spawn next shard
|
||||
// Wait few seconds to spawn next shard
|
||||
setTimeout(() => {
|
||||
const bucket = ws.buckets.get(shardId % ws.botGatewayData.sessionStartLimit.maxConcurrency);
|
||||
if (bucket) bucket.createNextShard.shift()?.();
|
||||
}, 5000);
|
||||
}, ws.spawnShardDelay);
|
||||
}
|
||||
|
||||
// Update the sequence number if it is present
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function heartbeat(shardId: number, interval: number) {
|
||||
shard.heartbeat.interval = interval;
|
||||
|
||||
shard.heartbeat.intervalId = setInterval(async () => {
|
||||
ws.log("DEBUG", `Running setInterval in heartbeat file.`);
|
||||
ws.log("DEBUG", `Running setInterval in heartbeat file. Shard: ${shardId}`);
|
||||
const currentShard = ws.shards.get(shardId);
|
||||
if (!currentShard) return;
|
||||
|
||||
|
||||
@@ -38,5 +38,4 @@ export async function startGateway(options: StartGatewayOptions) {
|
||||
ws.lastShardId = options.lastShardId || ws.botGatewayData.shards - 1;
|
||||
|
||||
ws.spawnShards(ws.firstShardId);
|
||||
await ws.cleanupLoadingShards();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ export const ws = {
|
||||
reshard: true,
|
||||
/** The percentage at which resharding should occur. */
|
||||
reshardPercentage: 80,
|
||||
/** The delay in milliseconds to wait before spawning next shard. OPTIMAL IS ABOVE 2500. YOU DON"T WANT TO HIT THE RATE LIMIT!!! */
|
||||
spawnShardDelay: 2500,
|
||||
/** The maximum shard Id number. Useful for zero-downtime updates or resharding. */
|
||||
maxShards: 0,
|
||||
/** Whether or not the resharder should automatically switch to LARGE BOT SHARDING when you are above 100K servers. */
|
||||
|
||||
Reference in New Issue
Block a user