fix: make property-assessor safer for whatsapp runs
This commit is contained in:
@@ -7,6 +7,7 @@ const MAX_SCROLL_PASSES = 12;
|
||||
const SCROLL_PAUSE_MS = 900;
|
||||
const LARGE_IMAGE_MIN_WIDTH = 300;
|
||||
const LARGE_IMAGE_MIN_HEIGHT = 200;
|
||||
const OPERATION_TIMEOUT_MS = Number(process.env.REAL_ESTATE_OPERATION_TIMEOUT_MS || 25000);
|
||||
|
||||
export function fail(message, details) {
|
||||
const payload = { error: message };
|
||||
@@ -38,6 +39,34 @@ export function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export async function runWithOperationTimeout(
|
||||
operationName,
|
||||
operation,
|
||||
{ timeoutMs = OPERATION_TIMEOUT_MS, onTimeout } = {}
|
||||
) {
|
||||
let timer;
|
||||
|
||||
try {
|
||||
return await Promise.race([
|
||||
operation(),
|
||||
new Promise((_, reject) => {
|
||||
timer = setTimeout(async () => {
|
||||
try {
|
||||
await onTimeout?.();
|
||||
} catch {
|
||||
// Ignore cleanup errors; the timeout is the primary failure.
|
||||
}
|
||||
reject(new Error(`${operationName} timed out after ${timeoutMs}ms`));
|
||||
}, timeoutMs);
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadCloakBrowser() {
|
||||
try {
|
||||
return await import("cloakbrowser");
|
||||
@@ -289,4 +318,3 @@ export function buildResult({
|
||||
notes,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user