feat(batchScrape): handle timeout
This commit is contained in:
@@ -276,10 +276,18 @@ async function processJob(job: Job & { id: string }, token: string) {
|
|||||||
});
|
});
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
|
|
||||||
const pipeline = await startWebScraperPipeline({
|
const pipeline = await Promise.race([
|
||||||
|
startWebScraperPipeline({
|
||||||
job,
|
job,
|
||||||
token,
|
token,
|
||||||
});
|
}),
|
||||||
|
...(job.data.scrapeOptions.timeout !== undefined ? [
|
||||||
|
(async () => {
|
||||||
|
await sleep(job.data.scrapeOptions.timeout);
|
||||||
|
throw new Error("timeout")
|
||||||
|
})(),
|
||||||
|
] : [])
|
||||||
|
]);
|
||||||
|
|
||||||
if (!pipeline.success) {
|
if (!pipeline.success) {
|
||||||
// TODO: let's Not do this
|
// TODO: let's Not do this
|
||||||
@@ -486,6 +494,9 @@ async function processJob(job: Job & { id: string }, token: string) {
|
|||||||
logger.info(`🐂 Job done ${job.id}`);
|
logger.info(`🐂 Job done ${job.id}`);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const isEarlyTimeout = error instanceof Error && error.message === "timeout";
|
||||||
|
|
||||||
|
if (!isEarlyTimeout) {
|
||||||
logger.error(`🐂 Job errored ${job.id} - ${error}`);
|
logger.error(`🐂 Job errored ${job.id} - ${error}`);
|
||||||
|
|
||||||
Sentry.captureException(error, {
|
Sentry.captureException(error, {
|
||||||
@@ -493,6 +504,9 @@ async function processJob(job: Job & { id: string }, token: string) {
|
|||||||
job: job.id,
|
job: job.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
logger.error(`🐂 Job timed out ${job.id}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (error instanceof CustomError) {
|
if (error instanceof CustomError) {
|
||||||
// Here we handle the error, then save the failed job
|
// Here we handle the error, then save the failed job
|
||||||
|
|||||||
Reference in New Issue
Block a user