1
0

fix: may accessing a non-existent schedule

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

View File

@ -2,7 +2,15 @@ import {DAY, HOUR, MINUTE} from "$std/datetime/constants.ts";
import {Client} from "https://deno.land/x/postgres@v0.19.3/mod.ts";
import {formatTimestampToPsql} from "lib/utils/formatTimestampToPostgre.ts";
import {SnapshotScheduleType} from "./schema.d.ts";
import logger from "../log/logger.ts";
import logger from "lib/log/logger.ts";
export async function snapshotScheduleExists(client: Client, id: number) {
const res = await client.queryObject<{ id: number }>(
`SELECT id FROM snapshot_schedule WHERE id = $1`,
[id],
);
return res.rows.length > 0;
}
/*
Returns true if the specified `aid` has at least one record with "pending" or "processing" status.

View File

@ -8,6 +8,7 @@ import {
hasAtLeast2Snapshots,
scheduleSnapshot,
setSnapshotStatus,
snapshotScheduleExists,
videoHasProcessingSchedule,
} from "lib/db/snapshotSchedule.ts";
import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts";
@ -153,6 +154,10 @@ export const takeSnapshotForVideoWorker = async (job: Job) => {
const task = snapshotTypeToTaskMap[type] ?? "snapshotVideo";
const client = await db.connect();
const retryInterval = type === "milestone" ? 5 * SECOND : 2 * MINUTE;
const exists = await snapshotScheduleExists(client, id);
if (!exists) {
return;
}
try {
if (await videoHasProcessingSchedule(client, aid)) {
return `ALREADY_PROCESSING`;