#223 - Fix CounterTask outputting its final count several times - #227
Merged
Merged
Conversation
… `flush()` may be called several times. Document that `flush()` implementations must be idempotent. Update documentation, add tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Description
Fixes #223.
flush()may be called several times on the same task during a process: once when an upstream iterable task finishes its iterations, then once for each resolved ancestor and for the task itself. The documentation already states thatflush()implementations must be idempotent, butCounterTaskis not: it outputs its final count on everyflush()call.Other flushable tasks of the bundles (
SimpleBatchTask,IterableBatchTask,InputFolderBrowserTask,ProcessLauncherTask,DoctrineBatchWriterTask) empty their buffer on the first flush, so the next calls output nothing.This PR:
CounterTask::flush()idempotent: a count already outputted by a previous flush is not outputted again (a new count, after new executions, is).FlushableTaskInterface(docblock) and in03-custom_tasks.md:flush()may be called several times and must be idempotent. Update02-task_types.mdandreference/tasks/counter_task.md, which describe the duplicated count.The new regression tests fail on
mainand pass with this fix. PHPUnit, PHPStan, PHP-CS-Fixer and Rector pass.Requirements
Breaking changes
None: the final count is outputted once instead of several times.
🤖 Generated with Claude Code