update: termination condition to time-based in classifyVideosWorker

This commit is contained in:
alikia2x (寒寒) 2025-05-31 12:23:01 +08:00
parent 1a20d5afe0
commit 2c83b79881
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6

View File

@ -51,14 +51,14 @@ export const classifyVideosWorker = async () => {
const videos = await getUnlabelledVideos(sql); const videos = await getUnlabelledVideos(sql);
logger.log(`Found ${videos.length} unlabelled videos`); logger.log(`Found ${videos.length} unlabelled videos`);
let i = 0; const startTime = new Date().getTime();
for (const aid of videos) { for (const aid of videos) {
if (i > 200) { const now = new Date().getTime();
if (now - startTime > 4.2 * MINUTE) {
await lockManager.releaseLock("classifyVideos"); await lockManager.releaseLock("classifyVideos");
return 10000 + i; return 1;
} }
await ClassifyVideoQueue.add("classifyVideo", { aid: Number(aid) }); await ClassifyVideoQueue.add("classifyVideo", { aid: Number(aid) });
i++;
} }
await lockManager.releaseLock("classifyVideos"); await lockManager.releaseLock("classifyVideos");
return 0; return 0;