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