mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 01:40:08 +00:00
fix: add type to gateway debug
This commit is contained in:
@@ -194,7 +194,7 @@ export interface GatewayManager {
|
||||
/** Tell the worker to begin identifying this shard */
|
||||
tellWorkerToIdentify: typeof tellWorkerToIdentify;
|
||||
/** Handle the different logs. Used for debugging. */
|
||||
debug: (text: string, ...args: any[]) => unknown;
|
||||
debug: (text: GatewayDebugEvents, ...args: any[]) => unknown;
|
||||
/** The methods related to resharding. */
|
||||
resharding: {
|
||||
/** Handles resharding the bot when necessary. */
|
||||
@@ -227,3 +227,21 @@ export interface GatewayManager {
|
||||
/** Calculates the number of shards to use based on the max concurrency */
|
||||
calculateMaxShards: typeof calculateMaxShards;
|
||||
}
|
||||
|
||||
export type GatewayDebugEvents =
|
||||
| "GW ERROR"
|
||||
| "GW CLOSED"
|
||||
| "GW CLOSED_RECONNECT"
|
||||
| "GW RAW"
|
||||
| "GW RECONNECT"
|
||||
| "GW INVALID_SESSION"
|
||||
| "GW RESUMED"
|
||||
| "GW RESUMING"
|
||||
| "GW IDENTIFYING"
|
||||
| "GW RAW_SEND"
|
||||
| "GW MAX REQUESTS"
|
||||
| "GW DEBUG"
|
||||
| "GW HEARTBEATING"
|
||||
| "GW HEARTBEATING_STARTED"
|
||||
| "GW HEARTBEATING_DETAILS"
|
||||
| "GW HEARTBEATING_CLOSED";
|
||||
|
||||
@@ -7,7 +7,7 @@ export async function resharder(
|
||||
oldGateway: GatewayManager,
|
||||
results: GetGatewayBot,
|
||||
) {
|
||||
oldGateway.debug("[Resharding] Starting the reshard process.");
|
||||
oldGateway.debug("GW DEBUG", "[Resharding] Starting the reshard process.");
|
||||
|
||||
const gateway = createGatewayManager({
|
||||
...oldGateway,
|
||||
@@ -40,7 +40,7 @@ export async function resharder(
|
||||
gateway.maxConcurrency = results.sessionStartLimit.maxConcurrency;
|
||||
// If more than 100K servers, begin switching to 16x sharding
|
||||
if (gateway.useOptimalLargeBotSharding) {
|
||||
gateway.debug("[Resharding] Using optimal large bot sharding solution.");
|
||||
gateway.debug("GW DEBUG", "[Resharding] Using optimal large bot sharding solution.");
|
||||
gateway.maxShards = gateway.calculateMaxShards(gateway.maxShards, results.sessionStartLimit.maxConcurrency);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export async function resharder(
|
||||
clearInterval(timer);
|
||||
await gateway.resharding.editGuildShardIds();
|
||||
await gateway.resharding.closeOldShards(oldGateway);
|
||||
gateway.debug("[Resharding] Complete.");
|
||||
gateway.debug("GW DEBUG", "[Resharding] Complete.");
|
||||
resolve(gateway);
|
||||
}, 30000);
|
||||
}) as Promise<GatewayManager>;
|
||||
@@ -113,7 +113,7 @@ export async function resharderCloseOldShards(oldGateway: GatewayManager) {
|
||||
|
||||
/** Handler that by default will check to see if resharding should occur. Can be overriden if you have multiple servers and you want to communicate through redis pubsub or whatever you prefer. */
|
||||
export async function startReshardingChecks(gateway: GatewayManager) {
|
||||
gateway.debug("[Resharding] Checking if resharding is needed.");
|
||||
gateway.debug("GW DEBUG", "[Resharding] Checking if resharding is needed.");
|
||||
|
||||
// TODO: is it possible to route this to REST?
|
||||
const results = (await fetch(`https://discord.com/api/gateway/bot`, {
|
||||
|
||||
@@ -8,7 +8,7 @@ export function resume(gateway: GatewayManager, shardId: number) {
|
||||
// Get the old data for this shard necessary for resuming
|
||||
const oldShard = gateway.shards.get(shardId);
|
||||
if (!oldShard) {
|
||||
return gateway.debug(`[Error] Trying to resume a shard (id: ${shardId}) that was not first identified.`);
|
||||
return gateway.debug("GW DEBUG", `[Error] Trying to resume a shard (id: ${shardId}) that was not first identified.`);
|
||||
}
|
||||
|
||||
// HOW TO CLOSE OLD SHARD SOCKET!!!
|
||||
|
||||
@@ -15,7 +15,7 @@ export function prepareBuckets(gateway: GatewayManager, firstShardId: number, la
|
||||
|
||||
// ORGANIZE ALL SHARDS INTO THEIR OWN BUCKETS
|
||||
for (let i = firstShardId; i < lastShardId; i++) {
|
||||
gateway.debug(`1. Running for loop in spawnShards function for shardId ${i}.`);
|
||||
gateway.debug("GW DEBUG", `1. Running for loop in spawnShards function for shardId ${i}.`);
|
||||
if (i >= gateway.maxShards) {
|
||||
continue;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export function prepareBuckets(gateway: GatewayManager, firstShardId: number, la
|
||||
export function spawnShards(gateway: GatewayManager, firstShardId = 0) {
|
||||
// PREPARES THE MAX SHARD COUNT BY CONCURRENCY
|
||||
if (gateway.useOptimalLargeBotSharding) {
|
||||
gateway.debug("[Spawning] Using optimal large bot sharding solution.");
|
||||
gateway.debug("GW DEBUG", "[Spawning] Using optimal large bot sharding solution.");
|
||||
gateway.maxShards = gateway.calculateMaxShards(gateway.maxShards, gateway.maxConcurrency);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ export function spawnShards(gateway: GatewayManager, firstShardId = 0) {
|
||||
|
||||
// SPREAD THIS OUT TO DIFFERENT WORKERS TO BEGIN STARTING UP
|
||||
gateway.buckets.forEach(async (bucket, bucketId) => {
|
||||
gateway.debug(`2. Running forEach loop in spawnShards function.`);
|
||||
gateway.debug("GW DEBUG", `2. Running forEach loop in spawnShards function.`);
|
||||
for (const [workerId, ...queue] of bucket.workers) {
|
||||
gateway.debug(`3. Running for of loop in spawnShards function.`);
|
||||
gateway.debug("GW DEBUG", `3. Running for of loop in spawnShards function.`);
|
||||
|
||||
for (const shardId of queue) {
|
||||
bucket.createNextShard.push(async () => {
|
||||
|
||||
Reference in New Issue
Block a user