fix: slow queue position updates

This commit is contained in:
pinks 2023-10-23 02:40:58 +02:00
parent dfa94e219d
commit 3a13d5c140
1 changed files with 13 additions and 13 deletions

View File

@ -306,24 +306,24 @@ async function processGenerationJob(
export async function updateGenerationQueue() { export async function updateGenerationQueue() {
while (true) { while (true) {
const jobs = await generationQueue.getAllJobs(); const jobs = await generationQueue.getAllJobs();
let index = 0;
for (const job of jobs) { await Promise.all(jobs.map(async (job) => {
if (job.lockUntil > new Date()) { if (job.status === "processing") {
// job is currently being processed, the worker will update its status message // if the job is processing, the worker will update its status message
continue; return;
} }
if (!job.state.replyMessage) {
// no status message, nothing to update // spread the updates in time randomly
continue; await delay(Math.random() * 3_000);
}
index++;
await bot.api.editMessageText( await bot.api.editMessageText(
job.state.replyMessage.chat.id, job.state.replyMessage.chat.id,
job.state.replyMessage.message_id, job.state.replyMessage.message_id,
`You are ${formatOrdinal(index)} in queue.`, `You are ${formatOrdinal(job.place)} in queue.`,
{ maxAttempts: 1 }, { maxAttempts: 1 },
).catch(() => undefined); ).catch(() => undefined);
} }));
await delay(3000);
await delay(10_000);
} }
} }