update: better task retrieval for snapshotTick

add: logging when snapshot the video
This commit is contained in:
alikia2x (寒寒) 2025-03-23 20:49:41 +08:00
parent 33c63fc29f
commit 9e764746fb
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
2 changed files with 13 additions and 5 deletions

View File

@ -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<SnapshotScheduleType>(query, []);
return res.rows;

View File

@ -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,