mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 08:20:08 +00:00
add queueMinuteTimestamp
This commit is contained in:
@@ -33,6 +33,7 @@ export async function identify(shardId: number, maxShards: number) {
|
||||
},
|
||||
queue: [],
|
||||
processingQueue: false,
|
||||
queueMinuteTimestamp: 0,
|
||||
});
|
||||
|
||||
socket.onopen = () => {
|
||||
|
||||
@@ -7,6 +7,7 @@ export async function processQueue(id: number) {
|
||||
if (!shard?.queue.length || shard.processingQueue) return;
|
||||
|
||||
shard.processingQueue = true;
|
||||
shard.queueMinuteTimestamp = Date.now();
|
||||
|
||||
let counter = 0;
|
||||
|
||||
@@ -16,6 +17,12 @@ export async function processQueue(id: number) {
|
||||
return;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
if (now - shard.queueMinuteTimestamp > 60000) {
|
||||
shard.queueMinuteTimestamp = now;
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
// Send a request that is next in line
|
||||
const request = shard.queue.shift();
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ export function spawnShards(firstShardId = 0) {
|
||||
|
||||
while (shardId !== undefined) {
|
||||
ws.log("DEBUG", "Running while loop in getMembers function.");
|
||||
await ws.tellClusterToIdentify(clusterId as number, shardId, bucketId);
|
||||
await ws.tellClusterToIdentify(clusterId, shardId, bucketId);
|
||||
shardId = queue.shift();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,8 @@ export interface DiscordenoShard {
|
||||
queue: WebSocketRequest[];
|
||||
/** Whether or not the queue for this shard is being processed. */
|
||||
processingQueue: boolean;
|
||||
/** When the first request for this minute has been sent. */
|
||||
queueMinuteTimestamp: number;
|
||||
}
|
||||
|
||||
export interface WebSocketRequest {
|
||||
|
||||
Reference in New Issue
Block a user