Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Latest
* [#483](https://github.com/cleverage/process-bundle/issues/483) Documentation: an exception thrown by `IterableTaskInterface::next()` makes the process fail right away with this exception, the `error_strategy` and the `error_outputs` of the task do not apply.

## Fixes
* [#491](https://github.com/cleverage/process-bundle/issues/491) `CounterTask`: `flush_every: 0` is rejected when the options are resolved, with a clear message, instead of failing on the first execution with `Modulo by zero`; a negative `flush_every`, which works as its absolute value, is deprecated. Update documentation, add tests.
* [#477](https://github.com/cleverage/process-bundle/issues/477) "Stop the process on the first invalid item" (`error_strategy: skip` and an error branch ending on a `StopTask`) ends as stopped when the failing task is finalizable (`csv_reader`, `xml_stream_reader`, `stat_counter`...): the error of the skipped item, kept by its state, was taken for a finalization failure and the process ended as failed. Add tests.
* [#473](https://github.com/cleverage/process-bundle/issues/473) A task failing with the `stop` error strategy makes the process fail even when its error branch stops the flow (`StopTask`, `ProcessState::stop()`): the failure was swallowed, the process ended as succeeded or stopped (`cleverage_process.end` event, exit code 0) and a parent process went on with a `null` output. Update documentation, add tests.
* [#485](https://github.com/cleverage/process-bundle/issues/485) The process returns the last output of its `end_point` passed on to the next tasks: the output of an execution whose output is ignored (skipped, filtered, failed with the `skip` strategy) was returned, e.g. `""` for a `skip_empty` end point whose last item is empty, or `null` for a filtered last item. Update documentation, add tests.
Expand Down Expand Up @@ -397,7 +398,6 @@ v3.2.2
* `\CleverAge\ProcessBundle\Exception\InvalidProcessConfigurationException` now displays the failing process code
* `\CleverAge\ProcessBundle\Transformer\TransformerTrait` now displays a more explicit message on wrong options type


v3.2.1
------

Expand All @@ -418,8 +418,6 @@ v3.2.0
There is no BC break for this version, but note that `sidus/base-bundle` has been removed from dependencies.
If you use it, it should already be inside your own composer.json.



Release v3.1
============

Expand All @@ -445,15 +443,13 @@ v3.1.5

* [GITHUB-120](https://github.com/cleverage/process-bundle/pull/120): FolderBrowserTask: Accept array type for `name_pattern` option


v3.1.4
------

### Features

* (_backport from v3.0.9_) Adding simple task to launch system commands


v3.1.3
------

Expand Down Expand Up @@ -509,7 +505,6 @@ v3.1.0
* [GITHUB-106](https://github.com/cleverage/process-bundle/issues/106): an entry-point cannot have an ancestor anymore.
The behaviour was undefined, and now it will throw an exception.


UPGRADE TO 2.0
==============

Expand All @@ -533,7 +528,6 @@ options:
<key>: <options>
```


UPGRADE TO 1.1
==============

Expand Down
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ as succeeded or stopped. To stop the process on purpose on the first error (not
on the failing task, as in the "Stop the process on the first invalid item" example of the
[StopTask](docs/reference/tasks/stop_task.md).

### Counter task

A negative `flush_every` option of the `counter` task works as its absolute value (`-3` as `3`): it is deprecated since
5.10 (`Since cleverage/process-bundle 5.10: A negative "flush_every" option of the counter task (-3) is deprecated...`)
and will be rejected in 6.0: use a positive integer. `flush_every: 0`, which failed on the first execution (`Modulo by
zero`), is now rejected when the options are resolved.

## v5.8

### Unknown task references
Expand Down
9 changes: 6 additions & 3 deletions docs/reference/tasks/counter_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Possible outputs
Options
-------

| Code | Type | Required | Default | Description |
|---------------|-------|:--------:|---------|-------------------------------------------------------|
| `flush_every` | `int` | **X** | | Output the count every N executions (N = this option) |
| Code | Type | Required | Default | Description |
|---------------|-------|:--------:|---------|--------------------------------------------------------------------------------------|
| `flush_every` | `int` | **X** | | Output the count every N executions (N = this option, a positive integer, see notes) |

Examples
--------
Expand Down Expand Up @@ -55,3 +55,6 @@ Notes
* `flush()` can be called several times during a process (see
[Advanced workflow](../../04-advanced_workflow.md)), e.g. once at the end of the upstream iteration and once when
the counter itself is resolved. The final count is only outputted by the first call; the next ones are skipped.
* `flush_every: 0` is rejected when the options are resolved (`InvalidOptionsException`) since 5.10: it failed on the
first execution (`Modulo by zero`). A negative value works as its absolute value (`-3` as `3`): it is deprecated since
5.10 and will be rejected in v6.0.
20 changes: 20 additions & 0 deletions src/Task/CounterTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
use CleverAge\ProcessBundle\Model\FlushableTaskInterface;
use CleverAge\ProcessBundle\Model\ProcessState;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
Expand Down Expand Up @@ -64,5 +66,23 @@ protected function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired(['flush_every']);
$resolver->setAllowedTypes('flush_every', ['int']);
$resolver->setNormalizer('flush_every', static function (Options $options, int $value): int {
// Modulo by zero
if (0 === $value) {
throw new InvalidOptionsException('The option "flush_every" of the counter task must be a positive integer (the count is output every "flush_every" executions), 0 given.');
}
// Works as its absolute value (sign of the modulo)
if ($value < 0) {
trigger_deprecation(
'cleverage/process-bundle',
'5.10',
'A negative "flush_every" option of the counter task (%d) is deprecated, it works as %d: use a positive integer. It will be rejected in v6.0.',
$value,
-$value,
);
}

return $value;
});
}
}
34 changes: 34 additions & 0 deletions tests/Task/CounterTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use CleverAge\ProcessBundle\Model\ProcessState;
use CleverAge\ProcessBundle\Task\CounterTask;
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;

#[\PHPUnit\Framework\Attributes\CoversClass(CounterTask::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(AbstractConfigurableTask::class)]
Expand Down Expand Up @@ -74,6 +75,39 @@ public function testFlushOutputsANewCountAfterNewExecutions(): void
self::assertNull($this->flush($task, $state));
}

/**
* A modulo by zero failed when executed.
*/
public function testZeroFlushEveryIsRejected(): void
{
$this->expectException(InvalidOptionsException::class);
$this->expectExceptionMessage('The option "flush_every" of the counter task must be a positive integer (the count is output every "flush_every" executions), 0 given.');

$this->createTask(0);
}

/**
* A negative value works as its absolute value (sign of the modulo): deprecated.
*/
public function testNegativeFlushEveryIsDeprecated(): void
{
$deprecations = [];
set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool {
$deprecations[] = $errstr;

return true;
}, \E_USER_DEPRECATED);
try {
[$task, $state] = $this->createTask(-2);
} finally {
restore_error_handler();
}

self::assertSame(['Since cleverage/process-bundle 5.10: A negative "flush_every" option of the counter task (-2) is deprecated, it works as 2: use a positive integer. It will be rejected in v6.0.'], $deprecations);
self::assertSame([null, 2, null, 4, null], $this->executeAll($task, $state, 5));
self::assertSame(5, $this->flush($task, $state));
}

/**
* @return array{CounterTask, ProcessState}
*/
Expand Down
Loading