From a178b7fc169a73121ac5991bdfdc52c9eadc256a Mon Sep 17 00:00:00 2001 From: alikia2x Date: Tue, 25 Mar 2025 04:52:19 +0800 Subject: [PATCH] update: force schedule for new songs --- lib/db/snapshotSchedule.ts | 4 ++-- lib/mq/exec/snapshotTick.ts | 2 +- lib/mq/task/collectSongs.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/db/snapshotSchedule.ts b/lib/db/snapshotSchedule.ts index 90e5b07..4816693 100644 --- a/lib/db/snapshotSchedule.ts +++ b/lib/db/snapshotSchedule.ts @@ -159,8 +159,8 @@ export async function getSnapshotScheduleCountWithinRange(client: Client, start: * @param aid The aid of the video. * @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; +export async function scheduleSnapshot(client: Client, aid: number, type: string, targetTime: number, force: boolean = false) { + if (await videoHasActiveSchedule(client, aid) && !force) return; let adjustedTime = new Date(targetTime); if (type !== "milestone" && type !== "new") { adjustedTime = await adjustSnapshotTime(new Date(targetTime), 1000, redis); diff --git a/lib/mq/exec/snapshotTick.ts b/lib/mq/exec/snapshotTick.ts index 7c3280c..55d3f70 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -227,7 +227,7 @@ export const takeSnapshotForVideoWorker = async (job: Job) => { if (viewsPerHour > 1000) { intervalMins = 15; } - await scheduleSnapshot(client, aid, type, Date.now() + intervalMins * MINUTE); + await scheduleSnapshot(client, aid, type, Date.now() + intervalMins * MINUTE, true); } 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 51dbb9f..b71aa3b 100644 --- a/lib/mq/task/collectSongs.ts +++ b/lib/mq/task/collectSongs.ts @@ -10,7 +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); + await scheduleSnapshot(client, aid, "new", Date.now() + 10 * MINUTE, true); logger.log(`Video ${aid} was added into the songs table.`, "mq", "fn:collectSongs"); } }