diff --git a/lib/db/snapshotSchedule.ts b/lib/db/snapshotSchedule.ts index 9ce304b..7968cba 100644 --- a/lib/db/snapshotSchedule.ts +++ b/lib/db/snapshotSchedule.ts @@ -185,11 +185,16 @@ function truncateTo5MinInterval(timestamp: Date): Date { export async function getSnapshotsInNextSecond(client: Client) { const query = ` - SELECT * - FROM snapshot_schedule - WHERE started_at - BETWEEN NOW() - INTERVAL '5 seconds' - AND NOW() + INTERVAL '1 seconds' + SELECT * + FROM snapshot_schedule + WHERE started_at <= NOW() + INTERVAL '1 seconds' AND status = 'pending' + ORDER BY + CASE + WHEN type = 'milestone' THEN 0 + ELSE 1 + END, + started_at + LIMIT 3; `; const res = await client.queryObject(query, []); return res.rows; diff --git a/lib/mq/task/getVideoStats.ts b/lib/mq/task/getVideoStats.ts index 8e3530a..3be1cd7 100644 --- a/lib/mq/task/getVideoStats.ts +++ b/lib/mq/task/getVideoStats.ts @@ -1,6 +1,7 @@ import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts"; import { getVideoInfo } from "lib/net/getVideoInfo.ts"; import { LatestSnapshotType } from "lib/db/schema.d.ts"; +import logger from "lib/log/logger.ts"; /* * Fetch video stats from bilibili API and insert into database @@ -39,6 +40,8 @@ export async function insertVideoSnapshot( [aid, views, danmakus, replies, likes, coins, shares, favorites], ); + logger.log(`Taken snapshot for video ${aid}.`, "net", "fn:insertVideoSnapshot"); + const snapshot: LatestSnapshotType = { aid, views,