Repository navigation
Conversation
The default (unbatched) completeJob/failJob functions returned promises that nobody awaited or attached a rejection handler to, so a non-retryable error recording a job's outcome became an unhandled rejection. Attach the same error handler as the batched path so the failure is logged with the job id, emitted as pool:fatalError, and the pool shuts down gracefully.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #641.
With the default
completeJobBatchDelay/failJobBatchDelayof-1, the unbatchedcompleteJob/failJobnow handle a failed outcome write the same way the batched path does. Before, they returned the promise frombatchCompleteJobs/batchFailJobs, which the worker does not await. If that query rejected with an errorwithRetriesdoes not retry (for exampleConnection terminated unexpectedly, which has nocode), nothing logged it or emitted an event. The job stayed locked until the stale-lock reset, and the process exited onunhandledRejectionif the app had no listener.In
src/main.tsthe batched error handlers move, with unchanged bodies, intohandleCompleteJobsError/handleFailJobsError. The batched path passes them tobatch()as before, and the unbatched path attaches them with.then(null, ...). With or without batching, a failure to record a job's outcome is now:pool:fatalErrorwithaction: "completeJob"or"failJob",workerPool.promiserejecting with the error.flowchart LR W[worker calls completeJob/failJob] --> D{batch delay >= 0?} D -- yes --> B["batch() errorHandler"] D -- "no (default -1)" --> U["batchCompleteJobs / batchFailJobs<br/>.then(null, handler)"] B --> H[handleCompleteJobsError / handleFailJobsError] U --> H H --> E[pool:fatalError + logger.error + gracefulShutdown]I kept the graceful shutdown because one failed unbatched write leaves the queue inconsistent in the same way as a failed batch. If you would rather log and emit only and keep the pool running, that is a small change.
Side effect: the unbatched
completeJob/failJobnow resolve after the handler runs instead of rejecting. Their declared return type isvoidand the worker ignores the value.__tests__/main.unbatchedOutcomeErrors.test.tsmakes the outcome query reject once with an error that has nocode, then checks thepool:fatalErroraction, the logged job id, and theworkerPool.promiserejection. Without the fix both cases fail:pool:fatalErrornever fires and Jest reports the unhandled rejection.