add queueMinuteTimestamp

This commit is contained in:
ITOH
2021-04-14 19:10:55 +02:00
parent 54ce040120
commit 4c097d4e17
4 changed files with 11 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ export async function identify(shardId: number, maxShards: number) {
},
queue: [],
processingQueue: false,
queueMinuteTimestamp: 0,
});
socket.onopen = () => {

View File

@@ -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();

View File

@@ -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();
}
}

View File

@@ -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 {