fix: failed to serialize bigint correctly
This commit is contained in:
parent
8652ac8fb7
commit
7768a202b2
@ -20,3 +20,20 @@ export async function getVideosNearMilestone(client: Client) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getLatestVideoSnapshot(client: Client, aid: number): Promise<null | LatestSnapshotType> {
|
||||||
|
const queryResult = await client.queryObject<LatestSnapshotType>(`
|
||||||
|
SELECT *
|
||||||
|
FROM latest_video_snapshot
|
||||||
|
WHERE aid = $1
|
||||||
|
`, [aid]);
|
||||||
|
if (queryResult.rows.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return queryResult.rows.map((row) => {
|
||||||
|
return {
|
||||||
|
...row,
|
||||||
|
aid: Number(row.aid),
|
||||||
|
}
|
||||||
|
})[0];
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Job } from "bullmq";
|
import { Job } from "bullmq";
|
||||||
import { db } from "lib/db/init.ts";
|
import { db } from "lib/db/init.ts";
|
||||||
import { getVideosNearMilestone } from "lib/db/snapshot.ts";
|
import {getLatestVideoSnapshot, getVideosNearMilestone} from "lib/db/snapshot.ts";
|
||||||
import {
|
import {
|
||||||
findClosestSnapshot,
|
findClosestSnapshot,
|
||||||
getLatestSnapshot,
|
getLatestSnapshot,
|
||||||
@ -42,7 +42,7 @@ export const snapshotTickWorker = async (_job: Job) => {
|
|||||||
const aid = Number(schedule.aid);
|
const aid = Number(schedule.aid);
|
||||||
await SnapshotQueue.add("snapshotVideo", {
|
await SnapshotQueue.add("snapshotVideo", {
|
||||||
aid: aid,
|
aid: aid,
|
||||||
id: schedule.id,
|
id: Number(schedule.id),
|
||||||
type: schedule.type ?? "normal",
|
type: schedule.type ?? "normal",
|
||||||
}, { priority });
|
}, { priority });
|
||||||
}
|
}
|
||||||
@ -131,8 +131,10 @@ export const regularSnapshotsWorker = async (_job: Job) => {
|
|||||||
for (const rawAid of aids) {
|
for (const rawAid of aids) {
|
||||||
const aid = Number(rawAid);
|
const aid = Number(rawAid);
|
||||||
if (await videoHasActiveSchedule(client, aid)) continue;
|
if (await videoHasActiveSchedule(client, aid)) continue;
|
||||||
|
const latestSnapshot = await getLatestVideoSnapshot(client, aid);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const targetTime = now + 24 * HOUR;
|
const lastSnapshotedAt = latestSnapshot?.time ?? now;
|
||||||
|
const targetTime = truncate(lastSnapshotedAt + 24 * HOUR, now + 1, Infinity);
|
||||||
await scheduleSnapshot(client, aid, "normal", targetTime);
|
await scheduleSnapshot(client, aid, "normal", targetTime);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -161,6 +163,10 @@ export const takeSnapshotForVideoWorker = async (job: Job) => {
|
|||||||
return `BILI_STATUS_${stat}`;
|
return `BILI_STATUS_${stat}`;
|
||||||
}
|
}
|
||||||
await setSnapshotStatus(client, id, "completed");
|
await setSnapshotStatus(client, id, "completed");
|
||||||
|
if (type === "normal") {
|
||||||
|
await scheduleSnapshot(client, aid, type, Date.now() + 24 * HOUR);
|
||||||
|
return `DONE`;
|
||||||
|
}
|
||||||
if (type !== "milestone") return `DONE`;
|
if (type !== "milestone") return `DONE`;
|
||||||
const eta = await getAdjustedShortTermETA(client, aid);
|
const eta = await getAdjustedShortTermETA(client, aid);
|
||||||
if (eta > 72) return "ETA_TOO_LONG";
|
if (eta > 72) return "ETA_TOO_LONG";
|
||||||
|
Loading…
Reference in New Issue
Block a user