Timeout jobs
const worker = new Worker('foo', async job => {
let controller = new AbortController();
const timer = setTimeout(() => controller.abort(), job.data.timeout);
try {
await doSomethingAbortable(controller.signal);
} catch(err) {
if (err.name == "AbortError") {
throw new UnrecoverableError("Timeout");
} else {
throw err;
}
} finally {
clearTimeout(timer);
}
});Last updated
Was this helpful?