mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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
27 lines
772 B
TypeScript
27 lines
772 B
TypeScript
import { env } from "../config.js";
|
|
|
|
type ToolCategory = "sharp" | "ai_cpu" | "ai_gpu" | "external" | "python";
|
|
|
|
const TIMEOUT_RATES: Record<ToolCategory, number> = {
|
|
sharp: 2,
|
|
ai_cpu: 30,
|
|
ai_gpu: 5,
|
|
external: 10,
|
|
python: 15,
|
|
};
|
|
|
|
export function computeTimeout(megapixels: number, category: ToolCategory, fileCount = 1): number {
|
|
if (env.PROCESSING_TIMEOUT_S > 0) {
|
|
return env.PROCESSING_TIMEOUT_S * 1000;
|
|
}
|
|
const perFile = Math.max(60_000, megapixels * TIMEOUT_RATES[category] * 1000);
|
|
return perFile * fileCount;
|
|
}
|
|
|
|
export function computeExternalToolTimeout(megapixels: number): number {
|
|
if (env.PROCESSING_TIMEOUT_S > 0) {
|
|
return env.PROCESSING_TIMEOUT_S * 1000;
|
|
}
|
|
return Math.max(60_000, megapixels * TIMEOUT_RATES.external * 1000);
|
|
}
|