2023-09-10 18:56:17 +00:00
|
|
|
import { Log } from "../deps.ts";
|
|
|
|
import { bot } from "../bot/mod.ts";
|
2023-09-13 09:50:22 +00:00
|
|
|
import { formatOrdinal } from "../common/utils.ts";
|
2023-09-10 18:56:17 +00:00
|
|
|
import { jobStore } from "../db/jobStore.ts";
|
|
|
|
|
|
|
|
const logger = () => Log.getLogger();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates status messages for jobs in the queue.
|
|
|
|
*/
|
|
|
|
export async function updateJobStatusMsgs(): Promise<never> {
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
2023-09-17 23:01:09 +00:00
|
|
|
const jobs = await jobStore.getBy("status.type", { value: "waiting" });
|
2023-09-10 18:56:17 +00:00
|
|
|
for (const [index, job] of jobs.entries()) {
|
2023-09-12 20:37:41 +00:00
|
|
|
if (job.value.status.type !== "waiting" || !job.value.status.message) continue;
|
2023-09-10 18:56:17 +00:00
|
|
|
await bot.api.editMessageText(
|
2023-09-12 20:37:41 +00:00
|
|
|
job.value.status.message.chat.id,
|
|
|
|
job.value.status.message.message_id,
|
2023-09-10 18:56:17 +00:00
|
|
|
`You are ${formatOrdinal(index + 1)} in queue.`,
|
2023-09-11 17:07:46 +00:00
|
|
|
{ maxAttempts: 1 },
|
2023-09-10 18:56:17 +00:00
|
|
|
).catch(() => undefined);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
logger().warning(`Updating job status messages failed: ${err}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|