- Processing queue limits OCR to 2 concurrent jobs across all sources (upload, email, folder watcher) - 50 MB file size cap enforced on uploads, email attachments, and folder watcher - Monday.com bulk sync now processes in batches of 5 with 1s delay between batches Made-with: Cursor
44 lines
992 B
TypeScript
44 lines
992 B
TypeScript
import { processFile } from "./ocr";
|
|
|
|
const MAX_CONCURRENT = 2;
|
|
const queue: QueueItem[] = [];
|
|
let running = 0;
|
|
|
|
type QueueItem = {
|
|
jobId: string;
|
|
fileName: string;
|
|
fileBuffer: Buffer;
|
|
isPdf: boolean;
|
|
resolve: (ids: string[]) => void;
|
|
reject: (err: unknown) => void;
|
|
};
|
|
|
|
function drain() {
|
|
while (running < MAX_CONCURRENT && queue.length > 0) {
|
|
const item = queue.shift()!;
|
|
running++;
|
|
processFile(item.jobId, item.fileName, item.fileBuffer, item.isPdf)
|
|
.then(item.resolve)
|
|
.catch(item.reject)
|
|
.finally(() => {
|
|
running--;
|
|
drain();
|
|
});
|
|
}
|
|
}
|
|
|
|
export function enqueueProcessing(
|
|
jobId: string,
|
|
fileName: string,
|
|
fileBuffer: Buffer,
|
|
isPdf: boolean
|
|
): Promise<string[]> {
|
|
return new Promise((resolve, reject) => {
|
|
queue.push({ jobId, fileName, fileBuffer, isPdf, resolve, reject });
|
|
drain();
|
|
});
|
|
}
|
|
|
|
export function getQueueStatus() {
|
|
return { running, queued: queue.length, maxConcurrent: MAX_CONCURRENT };
|
|
}
|