Provide jobs with an AbortSignal to attempt to gracefully interrupt jobs after shutdown timeout occurs #412
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
A job may be interrupted when a worker shuts down. In this case there are two mechanisms to ensure graceful interruption: the shutdown timeout and the execution context
AbortSignal
. The shutdown timeout is configured inWorkerOptions.timeout
. When a worker is instructed to stop (via process signal or server message), it will stop accepting new work (e.g.quiet
) and wait the configured duration for any in-progress jobs to complete uninterrupted. If this duration elapses and jobs are still in progress, these jobs will receive an AbortSignal viaContext.signal
. All jobs will beFAIL
ed on the Faktory server, allowing them to retry later.The abort signal can be used to interrupt asynchronous processes and perform some cleanup tasks before an abrupt exit (
process.exit
). After the abort signal is sent, a job will have 3 seconds to perform cleanup before the process is abruptly exited.Approach
Example - A long-running subprocess:
Closes #409
Closes #251