Repository navigation
fix: allow after commit callbacks to start a new unit of work - #49
Merged
Merged
Conversation
The unit of work manager now executes after commit callbacks as a single FIFO queue, drained by the outermost call to execute(). An after commit callback can start (and commit) a new unit of work, as the previous unit of work has committed. The new unit of work's after commit callbacks are added to the end of the queue, rather than resetting or draining the queue that is already in progress. Starting a unit of work while another is executing is still rejected. The fake unit of work now counts executions, and records which execution each entry in its sequence belongs to. As the manager handles re-attempts by executing the unit of work once per attempt, this distinguishes each attempt made by the manager. Closes #48 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 tasks
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.
Closes #48
Summary
UnitOfWorkManagernow lets an after commit callback start (and commit) a new unit of work, e.g. by dispatching a command that runs in a unit of work. Before this change it threwNot expecting unit of work manager to start a unit of work within an existing one., because the committed unit of work was still marked active while its after commit callbacks ran.Approach: a FIFO queue, not the "execute immediately" design in the issue
After commit callbacks now run as a single FIFO queue, drained by the outermost call to
execute():it_executes_additional_commit_callbacksis unchanged.execute(). It is not thrown by the nestedexecute(), so the nested call still returns its result.Compared with the design in the issue, this avoids running callbacks inside other callbacks, never makes
afterCommit()hold on to exceptions for its caller, and avoids the reset pitfall described in the issue.Other changes
beforeCommit()from an after commit callback, outside a new unit of work, now throwsCannot queue a before commit callback when not executing a unit of work.The previous message said the unit of work had been committed.FakeUnitOfWork:executionsproperty.sequenceentry now records which execution it belongs to, in the formatexecute:<execution>/<event>:<attempt>. The manager retries by calling the unit of work once per attempt, and previously every attempt made through the manager appeared asattempt:1.sequencewill need to update their tests. This is recorded under### Changedin the changelog.Tests
UnitOfWorkManagerTest: adds the scenarios from the issue, adjusted for FIFO. Covers queuing while draining, nested units of work and their retries, failures inside nested units of work, guards, and resetting state.tests/Integration/Testing/FakeUnitOfWorkManagerTest: runs the real manager overFakeUnitOfWork. Checks the fake is inactive when after commit callbacks run, and thatexecutions,attempts,commits,rollbacksandsequencerecord nested units of work correctly.FakeUnitOfWorkTest: updated to the new sequence format, with tests for counting executions.composer allpasses locally.🤖 Generated with Claude Code