Spaces:
Sleeping
Sleeping
| import { Queue } from "bullmq"; | |
| import { getRedisConnection } from "./redis"; | |
| import type { QCLine, QCModule } from "../qc/types"; | |
| export interface QCJobData { | |
| jobId: string; | |
| filename: string; | |
| lines: QCLine[]; | |
| language: string; | |
| module: QCModule; | |
| deliverableType: string; | |
| priority?: number; // 1 = urgent, 5 = normal (default) | |
| } | |
| let qcQueue: Queue<QCJobData> | null = null; | |
| export function getQCQueue(): Queue<QCJobData> { | |
| if (qcQueue) return qcQueue; | |
| qcQueue = new Queue<QCJobData>("qc-pipeline", { | |
| connection: getRedisConnection(), | |
| defaultJobOptions: { | |
| attempts: 3, | |
| backoff: { type: "exponential", delay: 30000 }, | |
| removeOnComplete: { count: 1000 }, | |
| removeOnFail: { count: 5000 }, | |
| }, | |
| }); | |
| return qcQueue; | |
| } | |
| export async function enqueueQCJob(data: QCJobData): Promise<string> { | |
| const queue = getQCQueue(); | |
| const job = await queue.add("qc-run", data, { | |
| priority: data.priority || 5, | |
| jobId: `qc-${data.jobId}`, | |
| }); | |
| console.log(`[QC:queue] Enqueued job ${job.id} for ${data.filename} (${data.lines.length} lines, priority=${data.priority || 5})`); | |
| return job.id!; | |
| } | |