fix(api): await logRequest in scrape controllers to prevent FK violation

logRequest was fire-and-forget in v1/scrape and v2/scrape controllers,
causing a race condition where the worker's logScrape could run before
the requests row existed, violating the scrapes_request_id_fkey foreign
key constraint. All other controllers (crawl, extract, etc.) already
await logRequest correctly.

Fixes API-NM
Fixes API-EG
This commit is contained in:
Abimael Martell
2026-02-26 16:42:02 -08:00
parent 7cdc066529
commit 68747ec4b1
2 changed files with 4 additions and 8 deletions

View File

@@ -67,7 +67,7 @@ export async function scrapeController(
account: req.account,
});
logRequest({
await logRequest({
id: jobId,
kind: "scrape",
api_version: "v1",
@@ -77,9 +77,7 @@ export async function scrapeController(
target_hint: req.body.url,
zeroDataRetention: zeroDataRetention || false,
api_key_id: req.acuc?.api_key_id ?? null,
}).catch(err =>
logger.warn("Background request log failed", { error: err, jobId }),
);
});
const origin = req.body.origin;
const timeout = req.body.timeout;

View File

@@ -126,7 +126,7 @@ export async function scrapeController(
});
if (!agentRequestId) {
logRequest({
await logRequest({
id: jobId,
kind: "scrape",
api_version: "v2",
@@ -136,9 +136,7 @@ export async function scrapeController(
target_hint: req.body.url,
zeroDataRetention: zeroDataRetention || false,
api_key_id: req.acuc?.api_key_id ?? null,
}).catch(err =>
logger.warn("Background request log failed", { error: err, jobId }),
);
});
}
setSpanAttributes(span, {