feat: add TransactionalParallelBatchNode with saga-style compensation#2
Open
weise25 wants to merge 1 commit into
Open
feat: add TransactionalParallelBatchNode with saga-style compensation#2weise25 wants to merge 1 commit into
weise25 wants to merge 1 commit into
Conversation
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.
Problem
AsyncParallelBatchNoderuns all items concurrently, but provides no rollback mechanism when one task fails. Because all tasks are awaited via a settle pattern, every task that completed before the failure has already produced its side effects — database writes, API calls, external mutations — and there is no automatic way to undo them.This leaves the system in a partial, inconsistent state:
SharedStorepopulated with partial results that downstream nodes cannot trustThe existing docblock warns about this, but places the entire burden on the caller.
Solution
This PR introduces
TransactionalParallelBatchNode, an abstract base class that implements the Saga pattern directly inside the framework.How it works
AsyncParallelBatchNode).$completedlist.Usage
Extend the class and implement
execAsync()as usual, plus the newcompensate()method:Caveats (documented in class docblock)
compensate()itself throws, the error is swallowed and the next compensation is attempted. The original exception is always re-thrown.AsyncParallelBatchNodeis unchanged — existing code is unaffected.Files changed
src/TransactionalParallelBatchNode.php— new file