From c12379134cb2b3b2335934d70c7aabdc5dbd2f12 Mon Sep 17 00:00:00 2001 From: alikia2x Date: Thu, 27 Mar 2025 03:44:41 +0800 Subject: [PATCH] update: error handling in bulk fetch --- lib/mq/exec/snapshotTick.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/mq/exec/snapshotTick.ts b/lib/mq/exec/snapshotTick.ts index 86c34ba..37daefa 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -249,13 +249,28 @@ export const takeBulkSnapshotForVideosWorker = async (job: Job) => { logger.log(`Taken snapshot for video ${aid} in bulk.`, "net", "fn:takeBulkSnapshotForVideosWorker"); } + await bulkSetSnapshotStatus(client, ids, "completed"); for (const aid of aidsToFetch) { const interval = await getRegularSnapshotInterval(client, aid); logger.log(`Scheduled regular snapshot for aid ${aid} in ${interval} hours.`, "mq"); await scheduleSnapshot(client, aid, "normal", Date.now() + interval * HOUR); } return `DONE`; - } finally { + } catch (e) { + if (e instanceof NetSchedulerError && e.code === "NO_PROXY_AVAILABLE") { + logger.warn( + `No available proxy for aid ${job.data.aid}.`, + "mq", + "fn:takeSnapshotForVideoWorker", + ); + await bulkSetSnapshotStatus(client, ids, "completed"); + await bulkScheduleSnapshot(client, aidsToFetch, "normal", Date.now() + 2 * MINUTE); + return; + } + logger.error(e as Error, "mq", "fn:takeSnapshotForVideoWorker"); + await bulkSetSnapshotStatus(client, ids, "failed"); + } + finally { client.release(); } };