fix: may accessing a non-existent schedule
This commit is contained in:
parent
3a0dd26c68
commit
35d58be8fd
@ -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.
|
||||
|
||||
@ -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`;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user