Dispatch WorkerStoppedEvent when the job throws - #52
Merged
Merged
Conversation
DavidBadura
force-pushed
the
worker-lifecycle
branch
from
October 2, 2026 15:20
bf15f8c to
a7f7d9d
Compare
Member
|
Why not a dedicated event? |
Member
Author
|
Usually you always want to do the same thing: clean up, no matter whether the worker stops because of a stop, signal, limits, or an exception. I don’t think it makes much sense to have a separate event for each of those, since you’d usually handle them all the same way anyway. Do you have a case where you’d actually want to distinguish between them? Right now you can already do that with |
This was referenced Oct 2, 2026
DanielBadura
approved these changes
Oct 2, 2026
If the job threw an exception, run() left without dispatching WorkerStoppedEvent, so cleanup listeners never ran in exactly the case they are most needed. The event is now always dispatched and carries the exception, which is rethrown afterwards.
DavidBadura
force-pushed
the
worker-lifecycle
branch
from
October 2, 2026 17:17
a7f7d9d to
de7212c
Compare
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.
When the job threw an exception, run() exited without dispatching WorkerStoppedEvent, so listeners that clean up on stop never ran in the error case. The loop is now wrapped in try/finally. WorkerStoppedEvent gets an optional exception property so listeners can tell a crash from a regular stop, and the exception is still rethrown, so the process exits with an error like before. The new constructor parameter has a default, so this is BC safe.