diff --git a/lib/db/snapshotSchedule.ts b/lib/db/snapshotSchedule.ts index 8d64f36..2c56f0d 100644 --- a/lib/db/snapshotSchedule.ts +++ b/lib/db/snapshotSchedule.ts @@ -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. diff --git a/lib/mq/exec/snapshotTick.ts b/lib/mq/exec/snapshotTick.ts index 519ecf3..9843788 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -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`;