fix: move filter model init to an earlier stage

This commit is contained in:
alikia2x (寒寒) 2025-02-22 22:29:30 +08:00
parent 95fa08b517
commit 73b96e869d
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
2 changed files with 5 additions and 3 deletions

View File

@ -1,7 +1,7 @@
import { Job } from "bullmq"; import { Job } from "bullmq";
import { db } from "lib/db/init.ts"; import { db } from "lib/db/init.ts";
import { getUnlabelledVideos, getVideoInfoFromAllData, insertVideoLabel} from "lib/db/allData.ts"; import { getUnlabelledVideos, getVideoInfoFromAllData, insertVideoLabel} from "lib/db/allData.ts";
import { classifyVideo, initializeModels } from "lib/ml/filter_inference.ts"; import { classifyVideo } from "lib/ml/filter_inference.ts";
import { ClassifyVideoQueue } from "lib/mq/index.ts"; import { ClassifyVideoQueue } from "lib/mq/index.ts";
import logger from "lib/log/logger.ts"; import logger from "lib/log/logger.ts";
import { lockManager } from "lib/mq/lockManager.ts"; import { lockManager } from "lib/mq/lockManager.ts";
@ -41,8 +41,6 @@ export const classifyVideosWorker = async () => {
lockManager.acquireLock("classifyVideos"); lockManager.acquireLock("classifyVideos");
await initializeModels();
const client = await db.connect(); const client = await db.connect();
const videos = await getUnlabelledVideos(client); const videos = await getUnlabelledVideos(client);
logger.log(`Found ${videos.length} unlabelled videos`) logger.log(`Found ${videos.length} unlabelled videos`)

View File

@ -4,6 +4,7 @@ import logger from "lib/log/logger.ts";
import { classifyVideosWorker, classifyVideoWorker } from "lib/mq/exec/classifyVideo.ts"; import { classifyVideosWorker, classifyVideoWorker } from "lib/mq/exec/classifyVideo.ts";
import { WorkerError } from "lib/mq/schema.ts"; import { WorkerError } from "lib/mq/schema.ts";
import { lockManager } from "lib/mq/lockManager.ts"; import { lockManager } from "lib/mq/lockManager.ts";
import { initializeModels } from "lib/ml/filter_inference.ts";
Deno.addSignalListener("SIGINT", async () => { Deno.addSignalListener("SIGINT", async () => {
logger.log("SIGINT Received: Shutting down workers...", "mq"); logger.log("SIGINT Received: Shutting down workers...", "mq");
@ -17,6 +18,9 @@ Deno.addSignalListener("SIGTERM", async () => {
Deno.exit(); Deno.exit();
}); });
await initializeModels();
const filterWorker = new Worker( const filterWorker = new Worker(
"classifyVideo", "classifyVideo",
async (job: Job) => { async (job: Job) => {