Skip to content

Dispatch WorkerStoppedEvent when the job throws - #52

Merged
DavidBadura merged 1 commit into
1.6.xfrom
worker-lifecycle
Oct 2, 2026
Merged

DavidBadura merged 1 commit into
1.6.xfrom
worker-lifecycle

Conversation

@DavidBadura

@DavidBadura DavidBadura commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

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.

@DavidBadura DavidBadura changed the title Dispatch WorkerStoppedEvent on job exceptions and allow rerunning a worker Dispatch WorkerStoppedEvent when the job throws Oct 2, 2026
@DavidBadura DavidBadura added this to the 1.6.0 milestone Oct 2, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Oct 2, 2026
@DanielBadura

Copy link
Copy Markdown
Member

Why not a dedicated event?

@DavidBadura

Copy link
Copy Markdown
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 exceptions !== null.

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
DavidBadura merged commit dc1b87b into 1.6.x Oct 2, 2026
15 of 16 checks passed
@DavidBadura
DavidBadura deleted the worker-lifecycle branch October 2, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants