fix: NaN caused by not converting date string to timestamp

This commit is contained in:
alikia2x (寒寒) 2025-03-23 20:41:13 +08:00
parent b654eb3643
commit 33c63fc29f
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
2 changed files with 3 additions and 2 deletions

View File

@ -34,6 +34,7 @@ export async function getLatestVideoSnapshot(client: Client, aid: number): Promi
return { return {
...row, ...row,
aid: Number(row.aid), aid: Number(row.aid),
time: new Date(row.time).getTime(),
} }
})[0]; })[0];
} }

View File

@ -12,7 +12,7 @@ import {
videoHasProcessingSchedule, videoHasProcessingSchedule,
} from "lib/db/snapshotSchedule.ts"; } from "lib/db/snapshotSchedule.ts";
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 { HOUR, MINUTE, SECOND } from "$std/datetime/constants.ts"; import { WEEK, HOUR, MINUTE, SECOND } from "$std/datetime/constants.ts";
import logger from "lib/log/logger.ts"; import logger from "lib/log/logger.ts";
import { SnapshotQueue } from "lib/mq/index.ts"; import { SnapshotQueue } from "lib/mq/index.ts";
import { insertVideoSnapshot } from "lib/mq/task/getVideoStats.ts"; import { insertVideoSnapshot } from "lib/mq/task/getVideoStats.ts";
@ -139,7 +139,7 @@ export const regularSnapshotsWorker = async (_job: Job) => {
const latestSnapshot = await getLatestVideoSnapshot(client, aid); const latestSnapshot = await getLatestVideoSnapshot(client, aid);
const now = Date.now(); const now = Date.now();
const lastSnapshotedAt = latestSnapshot?.time ?? now; const lastSnapshotedAt = latestSnapshot?.time ?? now;
const targetTime = truncate(lastSnapshotedAt + 24 * HOUR, now + 1, Infinity); const targetTime = truncate(lastSnapshotedAt + 24 * HOUR, now + 1, now + 100000 * WEEK);
await scheduleSnapshot(client, aid, "normal", targetTime); await scheduleSnapshot(client, aid, "normal", targetTime);
} }
} catch (e) { } catch (e) {