fix: clear PDF_TIMEOUT timers after successful render, fix test unhandled rejections
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 12m59s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 12m59s
This commit is contained in:
parent
f9caef82e6
commit
4473641ee1
2 changed files with 40 additions and 19 deletions
|
|
@ -244,6 +244,7 @@ export async function renderPdf(
|
|||
try {
|
||||
await page.setJavaScriptEnabled(false);
|
||||
const startTime = Date.now();
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
const result = await Promise.race([
|
||||
(async () => {
|
||||
await page.setContent(html, { waitUntil: "domcontentloaded", timeout: 15_000 });
|
||||
|
|
@ -264,10 +265,10 @@ export async function renderPdf(
|
|||
});
|
||||
return Buffer.from(pdf);
|
||||
})(),
|
||||
new Promise<never>((_, reject) =>
|
||||
setTimeout(() => reject(new Error("PDF_TIMEOUT")), 30_000)
|
||||
),
|
||||
]);
|
||||
new Promise<never>((_, reject) => {
|
||||
timeoutId = setTimeout(() => reject(new Error("PDF_TIMEOUT")), 30_000);
|
||||
}),
|
||||
]).finally(() => clearTimeout(timeoutId));
|
||||
const durationMs = Date.now() - startTime;
|
||||
logger.info(`PDF rendered in ${durationMs}ms (html, ${result.length} bytes)`);
|
||||
return { pdf: result, durationMs };
|
||||
|
|
@ -320,6 +321,7 @@ export async function renderUrlPdf(
|
|||
}
|
||||
}
|
||||
const startTime = Date.now();
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
const result = await Promise.race([
|
||||
(async () => {
|
||||
await page.goto(url, {
|
||||
|
|
@ -342,10 +344,10 @@ export async function renderUrlPdf(
|
|||
});
|
||||
return Buffer.from(pdf);
|
||||
})(),
|
||||
new Promise<never>((_, reject) =>
|
||||
setTimeout(() => reject(new Error("PDF_TIMEOUT")), 30_000)
|
||||
),
|
||||
]);
|
||||
new Promise<never>((_, reject) => {
|
||||
timeoutId = setTimeout(() => reject(new Error("PDF_TIMEOUT")), 30_000);
|
||||
}),
|
||||
]).finally(() => clearTimeout(timeoutId));
|
||||
const durationMs = Date.now() - startTime;
|
||||
logger.info(`PDF rendered in ${durationMs}ms (url, ${result.length} bytes)`);
|
||||
return { pdf: result, durationMs };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue