fix: prevent dispatchRegularSnapshots from running for too long

This commit is contained in:
alikia2x (寒寒) 2025-03-24 00:57:48 +08:00
parent 0be961e709
commit 9060d28823
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6

View File

@ -108,7 +108,6 @@ const getAdjustedShortTermETA = async (client: Client, aid: number) => {
export const collectMilestoneSnapshotsWorker = async (_job: Job) => {
const client = await db.connect();
const startedAt = Date.now();
try {
const videos = await getVideosNearMilestone(client);
for (const video of videos) {
@ -122,9 +121,6 @@ export const collectMilestoneSnapshotsWorker = async (_job: Job) => {
const delay = truncate(scheduledNextSnapshotDelay, minInterval, maxInterval);
const targetTime = now + delay;
await scheduleSnapshot(client, aid, "milestone", targetTime);
if (now - startedAt > 25 * MINUTE) {
return;
}
}
} catch (e) {
logger.error(e as Error, "mq", "fn:collectMilestoneSnapshotsWorker");
@ -135,6 +131,7 @@ export const collectMilestoneSnapshotsWorker = async (_job: Job) => {
export const regularSnapshotsWorker = async (_job: Job) => {
const client = await db.connect();
const startedAt = Date.now();
try {
const aids = await getVideosWithoutActiveSnapshotSchedule(client);
for (const rawAid of aids) {
@ -144,6 +141,9 @@ export const regularSnapshotsWorker = async (_job: Job) => {
const lastSnapshotedAt = latestSnapshot?.time ?? now;
const targetTime = truncate(lastSnapshotedAt + 24 * HOUR, now + 1, now + 100000 * WEEK);
await scheduleSnapshot(client, aid, "normal", targetTime);
if (now - startedAt > 25 * MINUTE) {
return;
}
}
} catch (e) {
logger.error(e as Error, "mq", "fn:regularSnapshotsWorker");