temp: schedule for new songs

This commit is contained in:
alikia2x (寒寒) 2025-03-24 04:40:10 +08:00
parent 0a73d28623
commit 42db333d1a
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
3 changed files with 10 additions and 3 deletions

View File

@ -162,7 +162,7 @@ export async function getSnapshotScheduleCountWithinRange(client: Client, start:
export async function scheduleSnapshot(client: Client, aid: number, type: string, targetTime: number) { export async function scheduleSnapshot(client: Client, aid: number, type: string, targetTime: number) {
if (await videoHasActiveSchedule(client, aid)) return; if (await videoHasActiveSchedule(client, aid)) return;
let adjustedTime = new Date(targetTime); let adjustedTime = new Date(targetTime);
if (type !== "milestone") { if (type !== "milestone" && type !== "new") {
adjustedTime = await adjustSnapshotTime(new Date(targetTime), 1000, redis); adjustedTime = await adjustSnapshotTime(new Date(targetTime), 1000, redis);
} }
logger.log(`Scheduled snapshot for ${aid} at ${adjustedTime.toISOString()}`, "mq", "fn:scheduleSnapshot"); logger.log(`Scheduled snapshot for ${aid} at ${adjustedTime.toISOString()}`, "mq", "fn:scheduleSnapshot");

View File

@ -30,6 +30,7 @@ const priorityMap: { [key: string]: number } = {
const snapshotTypeToTaskMap: { [key: string]: string } = { const snapshotTypeToTaskMap: { [key: string]: string } = {
"milestone": "snapshotMilestoneVideo", "milestone": "snapshotMilestoneVideo",
"normal": "snapshotVideo", "normal": "snapshotVideo",
"new": "snapshotMilestoneVideo"
}; };
export const snapshotTickWorker = async (_job: Job) => { export const snapshotTickWorker = async (_job: Job) => {
@ -164,7 +165,6 @@ export const regularSnapshotsWorker = async (_job: Job) => {
const now = Date.now(); const now = Date.now();
const lastSnapshotedAt = latestSnapshot?.time ?? now; const lastSnapshotedAt = latestSnapshot?.time ?? now;
const interval = await getRegularSnapshotInterval(client, aid); 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); const targetTime = truncate(lastSnapshotedAt + interval * HOUR, now + 1, now + 100000 * WEEK);
await scheduleSnapshot(client, aid, "normal", targetTime); await scheduleSnapshot(client, aid, "normal", targetTime);
if (now - startedAt > 25 * MINUTE) { if (now - startedAt > 25 * MINUTE) {
@ -203,8 +203,12 @@ export const takeSnapshotForVideoWorker = async (job: Job) => {
} }
await setSnapshotStatus(client, id, "completed"); await setSnapshotStatus(client, id, "completed");
if (type === "normal") { 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`; return `DONE`;
}
else if (type === "new") {
} }
if (type !== "milestone") return `DONE`; if (type !== "milestone") return `DONE`;
const eta = await getAdjustedShortTermETA(client, aid); const eta = await getAdjustedShortTermETA(client, aid);

View File

@ -1,6 +1,8 @@
import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts"; import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts";
import { aidExistsInSongs, getNotCollectedSongs } from "lib/db/songs.ts"; import { aidExistsInSongs, getNotCollectedSongs } from "lib/db/songs.ts";
import logger from "lib/log/logger.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) { export async function collectSongs(client: Client) {
const aids = await getNotCollectedSongs(client); const aids = await getNotCollectedSongs(client);
@ -8,6 +10,7 @@ export async function collectSongs(client: Client) {
const exists = await aidExistsInSongs(client, aid); const exists = await aidExistsInSongs(client, aid);
if (exists) continue; if (exists) continue;
await insertIntoSongs(client, aid); 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"); logger.log(`Video ${aid} was added into the songs table.`, "mq", "fn:collectSongs");
} }
} }