From f00c0b82f9be8b50612116d05d99cef6d65b6cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20M=C3=B3ricz?= Date: Tue, 24 Sep 2024 21:56:22 +0200 Subject: [PATCH] fix(v1/scrape): add total wait specified in request to timeout --- apps/api/src/controllers/v1/scrape.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/api/src/controllers/v1/scrape.ts b/apps/api/src/controllers/v1/scrape.ts index f0744c2..ebbabc0 100644 --- a/apps/api/src/controllers/v1/scrape.ts +++ b/apps/api/src/controllers/v1/scrape.ts @@ -54,9 +54,11 @@ export async function scrapeController( jobPriority ); + const totalWait = (req.body.waitFor ?? 0) + (req.body.actions ?? []).reduce((a,x) => (x.type === "wait" ? x.milliseconds : 0) + a, 0); + let doc: any | undefined; try { - doc = (await waitForJob(job.id, timeout))[0]; + doc = (await waitForJob(job.id, timeout + totalWait))[0]; } catch (e) { Logger.error(`Error in scrapeController: ${e}`); if (e instanceof Error && e.message.startsWith("Job wait")) {