Skip to content

#223 - Fix CounterTask outputting its final count several times - #227

Merged
njoubert-cleverage merged 2 commits into
mainfrom
223
Sep 28, 2026
Merged

njoubert-cleverage merged 2 commits into
mainfrom
223

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

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 that flush() implementations must be idempotent, but CounterTask is not: it outputs its final count on every flush() 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:

  • Make CounterTask::flush() idempotent: a count already outputted by a previous flush is not outputted again (a new count, after new executions, is).
  • Document the contract on FlushableTaskInterface (docblock) and in 03-custom_tasks.md: flush() may be called several times and must be idempotent. Update 02-task_types.md and reference/tasks/counter_task.md, which describe the duplicated count.
  • Changing the engine so that each task is flushed only once is out of scope (see Rewrite the ProcessManager to simplify each functionnality #88).
  • Add tests.

The new regression tests fail on main and pass with this fix. PHPUnit, PHPStan, PHP-CS-Fixer and Rector pass.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None: the final count is outputted once instead of several times.

🤖 Generated with Claude Code

njoubert-cleverage and others added 2 commits September 28, 2026 16:47
… `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>
@njoubert-cleverage
njoubert-cleverage merged commit d64a3c9 into main Sep 28, 2026
3 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CounterTask outputs its final count several times, as flush() may be called several times

1 participant