From 33c63fc29f3eb7d6b7e1bec9e97d5db97142b1f9 Mon Sep 17 00:00:00 2001 From: alikia2x Date: Sun, 23 Mar 2025 20:41:13 +0800 Subject: [PATCH] fix: NaN caused by not converting date string to timestamp --- lib/db/snapshot.ts | 1 + lib/mq/exec/snapshotTick.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/db/snapshot.ts b/lib/db/snapshot.ts index 09f14b5..34ffe82 100644 --- a/lib/db/snapshot.ts +++ b/lib/db/snapshot.ts @@ -34,6 +34,7 @@ export async function getLatestVideoSnapshot(client: Client, aid: number): Promi return { ...row, aid: Number(row.aid), + time: new Date(row.time).getTime(), } })[0]; } diff --git a/lib/mq/exec/snapshotTick.ts b/lib/mq/exec/snapshotTick.ts index 0919164..be0b3e2 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -12,7 +12,7 @@ import { videoHasProcessingSchedule, } from "lib/db/snapshotSchedule.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 { SnapshotQueue } from "lib/mq/index.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 now = Date.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); } } catch (e) {