mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat: dynamic timeouts — scale with image size, respect PROCESSING_TIMEOUT_S
Create timeout.ts utility for dynamic timeout computation. Replace hardcoded timeouts across the stack: - tool-factory worker: 30s → dynamic based on megapixels - Python bridge default: 300s → 600s (or env override) - background-removal: fixed → dynamic based on image size - OCR: fixed 600s → dynamic based on image size - seam-carving: 120s → dynamic based on image size - ExifTool: 30s → 60s - HEIC converter: 30s → 120s - SQLite busy_timeout: 5s → 10s
This commit is contained in:
@@ -15,6 +15,7 @@ import { sanitizeFilename } from "../lib/filename.js";
|
||||
import { decodeHeic } from "../lib/heic-converter.js";
|
||||
import type { WorkerInput, WorkerOutput } from "../lib/image-worker.js";
|
||||
import { sanitizeSvg } from "../lib/svg-sanitize.js";
|
||||
import { computeTimeout } from "../lib/timeout.js";
|
||||
import { getWorkerPool } from "../lib/worker-pool.js";
|
||||
import { createWorkspace } from "../lib/workspace.js";
|
||||
|
||||
@@ -227,8 +228,11 @@ export function createToolRoute<T>(app: FastifyInstance, config: ToolRouteConfig
|
||||
filename,
|
||||
inputFormat: validation.format,
|
||||
};
|
||||
const meta = await sharp(fileBuffer).metadata();
|
||||
const megapixels = ((meta.width ?? 0) * (meta.height ?? 0)) / 1_000_000;
|
||||
const timeoutMs = computeTimeout(megapixels, "sharp");
|
||||
const workerResult: WorkerOutput = await pool.run(workerInput, {
|
||||
signal: AbortSignal.timeout(30_000),
|
||||
signal: AbortSignal.timeout(timeoutMs),
|
||||
});
|
||||
result = {
|
||||
buffer: Buffer.from(workerResult.buffer),
|
||||
|
||||
Reference in New Issue
Block a user