Basic Timeout Pattern
The basic concept is to set up a timeout callback that will abort the job processing, and throw anUnrecoverableError to avoid retries:
Timeout with Fetch API
When working with HTTP requests, you can use the nativeAbortController with the Fetch API:
response.text() to also throw an Abort exception.
Timeout with Retries
If you want timeouts to trigger retries instead of immediate failure, throw a regularError instead of UnrecoverableError:
Adding Jobs with Timeout
Summary
While it is possible to implement timeout in your jobs, the mechanism to do it may vary depending on the type of asynchronous operations your job is performing. In many cases, usingAbortController in combination with a setTimeout is more than enough.
For sandboxed processors, see Timeout for Sandboxed Processors for special considerations.
Related Resources
Cancelling Jobs
Learn about job cancellation with AbortSignal
UnrecoverableError
API reference for UnrecoverableError
