fix: only 1 pending task at a time

This commit is contained in:
alikia2x (寒寒) 2025-03-23 21:36:40 +08:00
parent 9e764746fb
commit 3a0dd26c68
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
2 changed files with 1 additions and 3 deletions

View File

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

View File

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