From 3a0dd26c682d8e135be419d230c9570447d8d10a Mon Sep 17 00:00:00 2001 From: alikia2x Date: Sun, 23 Mar 2025 21:36:40 +0800 Subject: [PATCH] fix: only 1 pending task at a time --- lib/db/snapshotSchedule.ts | 1 + lib/mq/exec/snapshotTick.ts | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/db/snapshotSchedule.ts b/lib/db/snapshotSchedule.ts index 7968cba..8d64f36 100644 --- a/lib/db/snapshotSchedule.ts +++ b/lib/db/snapshotSchedule.ts @@ -98,6 +98,7 @@ export async function getSnapshotScheduleCountWithinRange(client: Client, start: * @param targetTime Scheduled time for snapshot. (Timestamp in milliseconds) */ export async function scheduleSnapshot(client: Client, aid: number, type: string, targetTime: number) { + if (await videoHasActiveSchedule(client, aid)) return; const allowedCount = type === "milestone" ? 2000 : 800; const adjustedTime = await adjustSnapshotTime(client, new Date(targetTime), allowedCount); logger.log(`Scheduled snapshot for ${aid} at ${adjustedTime.toISOString()}`, "mq", "fn:scheduleSnapshot"); diff --git a/lib/mq/exec/snapshotTick.ts b/lib/mq/exec/snapshotTick.ts index be0b3e2..519ecf3 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -8,7 +8,6 @@ import { hasAtLeast2Snapshots, scheduleSnapshot, setSnapshotStatus, - videoHasActiveSchedule, videoHasProcessingSchedule, } from "lib/db/snapshotSchedule.ts"; import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts"; @@ -111,7 +110,6 @@ export const collectMilestoneSnapshotsWorker = async (_job: Job) => { const videos = await getVideosNearMilestone(client); for (const video of videos) { const aid = Number(video.aid); - if (await videoHasActiveSchedule(client, aid)) continue; const eta = await getAdjustedShortTermETA(client, aid); if (eta > 72) continue; const now = Date.now(); @@ -135,7 +133,6 @@ export const regularSnapshotsWorker = async (_job: Job) => { const aids = await getVideosWithoutActiveSnapshotSchedule(client); for (const rawAid of aids) { const aid = Number(rawAid); - if (await videoHasActiveSchedule(client, aid)) continue; const latestSnapshot = await getLatestVideoSnapshot(client, aid); const now = Date.now(); const lastSnapshotedAt = latestSnapshot?.time ?? now;