feat(scrape): record job result in span

This commit is contained in:
Gergő Móricz 2024-08-22 16:00:13 +02:00
parent 5ca36fe9fc
commit 6d92b8524d

View File

@ -49,10 +49,13 @@ export async function scrapeHelper(
}, {}, jobId); }, {}, jobId);
let doc; let doc;
const err = await Sentry.startSpanManual({ name: "Wait for job to finish", op: "bullmq.wait", attributes: { job: jobId } }, async (span) => {
try { try {
doc = (await job.waitUntilFinished(scrapeQueueEvents, timeout))[0]; //60 seconds timeout doc = (await job.waitUntilFinished(scrapeQueueEvents, timeout))[0]
} catch (e) { } catch (e) {
if (e instanceof Error && e.message.startsWith("Job wait")) { if (e instanceof Error && e.message.startsWith("Job wait")) {
span.setAttribute("timedOut", true).end();
return { return {
success: false, success: false,
error: "Request timed out", error: "Request timed out",
@ -62,6 +65,13 @@ export async function scrapeHelper(
throw e; throw e;
} }
} }
span.setAttribute("result", JSON.stringify(doc)).end();
return null;
});
if (err !== null) {
return err;
}
await job.remove(); await job.remove();