diff --git a/lib/db/snapshotSchedule.ts b/lib/db/snapshotSchedule.ts index 702c6dd..e77f225 100644 --- a/lib/db/snapshotSchedule.ts +++ b/lib/db/snapshotSchedule.ts @@ -162,7 +162,7 @@ export async function getSnapshotScheduleCountWithinRange(client: Client, start: export async function scheduleSnapshot(client: Client, aid: number, type: string, targetTime: number) { if (await videoHasActiveSchedule(client, aid)) return; let adjustedTime = new Date(targetTime); - if (type !== "milestone") { + if (type !== "milestone" && type !== "new") { adjustedTime = await adjustSnapshotTime(new Date(targetTime), 1000, redis); } 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 4d63c6e..de7b039 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -30,6 +30,7 @@ const priorityMap: { [key: string]: number } = { const snapshotTypeToTaskMap: { [key: string]: string } = { "milestone": "snapshotMilestoneVideo", "normal": "snapshotVideo", + "new": "snapshotMilestoneVideo" }; export const snapshotTickWorker = async (_job: Job) => { @@ -164,7 +165,6 @@ export const regularSnapshotsWorker = async (_job: Job) => { const now = Date.now(); const lastSnapshotedAt = latestSnapshot?.time ?? now; const interval = await getRegularSnapshotInterval(client, aid); - logger.debug(`${interval} hours for aid ${aid}`, "mq") const targetTime = truncate(lastSnapshotedAt + interval * HOUR, now + 1, now + 100000 * WEEK); await scheduleSnapshot(client, aid, "normal", targetTime); if (now - startedAt > 25 * MINUTE) { @@ -203,8 +203,12 @@ export const takeSnapshotForVideoWorker = async (job: Job) => { } await setSnapshotStatus(client, id, "completed"); if (type === "normal") { - await scheduleSnapshot(client, aid, type, Date.now() + 24 * HOUR); + const interval = await getRegularSnapshotInterval(client, aid); + await scheduleSnapshot(client, aid, type, Date.now() + interval * HOUR); return `DONE`; + } + else if (type === "new") { + } if (type !== "milestone") return `DONE`; const eta = await getAdjustedShortTermETA(client, aid); diff --git a/lib/mq/task/collectSongs.ts b/lib/mq/task/collectSongs.ts index 9c49823..51dbb9f 100644 --- a/lib/mq/task/collectSongs.ts +++ b/lib/mq/task/collectSongs.ts @@ -1,6 +1,8 @@ import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts"; import { aidExistsInSongs, getNotCollectedSongs } from "lib/db/songs.ts"; import logger from "lib/log/logger.ts"; +import { scheduleSnapshot } from "lib/db/snapshotSchedule.ts"; +import { MINUTE } from "$std/datetime/constants.ts"; export async function collectSongs(client: Client) { const aids = await getNotCollectedSongs(client); @@ -8,6 +10,7 @@ export async function collectSongs(client: Client) { const exists = await aidExistsInSongs(client, aid); if (exists) continue; await insertIntoSongs(client, aid); + await scheduleSnapshot(client, aid, "new", Date.now() + 10 * MINUTE); logger.log(`Video ${aid} was added into the songs table.`, "mq", "fn:collectSongs"); } }