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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Latest
------

## Changes
* [#414](https://github.com/cleverage/process-bundle/issues/414) Listing a task several times in the `outputs` or the `error_outputs` of a task is deprecated: it is executed once per occurrence, an exception will be thrown in v6.0 (see `UPGRADE.md`). Update documentation, add tests.
* [#406](https://github.com/cleverage/process-bundle/issues/406) Documentation: non-interactive install with Symfony Flex (`allow-contrib`, the recipe being in `recipes-contrib`), `$kernel` constructor parameter renamed in 5.4 in `UPGRADE.md` (breaks the named arguments), prerequisites of the functional test of `06-testing.md` (`KERNEL_CLASS`, test database with the UI bundle).
* [#392](https://github.com/cleverage/process-bundle/issues/392) Documentation: reset of the process configurations between two messages of a worker (`kernel.reset`, #355), permissions of the JSON buffer of `process_launcher`, `ProcessManager` subclasses in `UPGRADE.md` (v5.5), broken link in the CHANGELOG.

Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ If you used the former name (with underscores) of such a code, it still works bu
`process_executor` tasks, the task references (`outputs`, `error_outputs`, `entry_point`, `end_point`), the transformer
references and the applications storing process codes (e.g. the schedules of the UI bundle).

### Duplicate task references

Listing a task several times in the `outputs` or the `error_outputs` of a task (e.g. `outputs: [next, next]`) is
deprecated since 5.7 (`Since cleverage/process-bundle 5.7: Listing the task "next" several times in the "outputs"...`):
the task is executed once per occurrence, and an exception will be thrown in 6.0. List it once.

## v5.6

Two deprecations, and some behaviours change: check the points below.
Expand Down
4 changes: 3 additions & 1 deletion docs/reference/02-task_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ added at runtime) is fetched from the service container, which requires a public
**options**: optional list of parameters to pass to the task. String values can contain `{{ key }}` placeholders that
are replaced by the process [contextual values](../01-quick_start.md#contextual-values).

**outputs**: optional list of following tasks, receiving the output of this task. It can be a simple string.
**outputs**: optional list of following tasks, receiving the output of this task. It can be a simple string. A task
listed several times is executed once per occurrence: this is deprecated since 5.7, and will throw an exception in 6.0
(also for `error_outputs`).

**error_outputs**: optional list of following tasks, receiving the error output of this task (by default its input when
an error occurs). It can be a simple string. See [errors and skips](../04-advanced_workflow.md#errors-and-skips).
Expand Down
31 changes: 31 additions & 0 deletions src/Registry/ProcessConfigurationRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ protected function resolveConfiguration(string $processCode): void

// Check the task references, the links below would fail with a message naming neither the process nor the task
$this->checkTaskReferences($processCode, $rawProcessConfiguration, $taskConfigurations, $errorOutputsKeys);
$this->checkDuplicateTaskReferences($processCode, $taskConfigurations, $errorOutputsKeys);

// Set links between tasks
foreach ($taskConfigurations as $taskConfig) {
Expand Down Expand Up @@ -322,6 +323,36 @@ protected function checkTaskReferences(
}
}

/**
* A task listed several times in the outputs of a task is executed once per occurrence (deprecated).
*
* @param TaskConfiguration[] $taskConfigurations indexed by task code
* @param array<string, string> $errorOutputsKeys "errors" for the tasks using this deprecated key
*/
private function checkDuplicateTaskReferences(string $processCode, array $taskConfigurations, array $errorOutputsKeys): void
{
foreach ($taskConfigurations as $taskCode => $taskConfig) {
$references = [
'outputs' => $taskConfig->getOutputs(),
$errorOutputsKeys[$taskCode] ?? 'error_outputs' => $taskConfig->getErrorOutputs(),
];
foreach ($references as $key => $codes) {
foreach (array_unique(array_diff_assoc($codes, array_unique($codes))) as $duplicateCode) {
// @deprecated since 5.7, an exception will be thrown in v6.0
trigger_deprecation(
'cleverage/process-bundle',
'5.7',
'Listing the task "%s" several times in the "%s" of the task "%s" of the process "%s" is deprecated: it is executed once per occurrence. In v6.0, an exception will be thrown.',
$duplicateCode,
$key,
$taskCode,
$processCode,
);
}
}
}
}

protected function markErrorBranch(TaskConfiguration $taskConfig, bool $isErrorBranch = true): void
{
if ($taskConfig->isInErrorBranch() !== $isErrorBranch) {
Expand Down
34 changes: 34 additions & 0 deletions tests/Registry/ProcessConfigurationRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,38 @@ public function testTheFormerNamesAreDeprecated(): void
'Since cleverage/process-bundle 5.7: Referencing the task "next-task" of the process "demo.x-y" by the name "next_task" in "outputs", with underscores instead of dashes, is deprecated: use its code "next-task". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.',
], $deprecations);
}

/**
* A task listed several times in the outputs is executed once per occurrence: deprecated, it will throw in v6.0.
*/
public function testDuplicateTaskReferencesAreDeprecated(): void
{
$registry = new ProcessConfigurationRegistry([
'test.process' => $this->rawProcess([
'first' => ['outputs' => ['next', 'other', 'next', 'next'], 'error_outputs' => ['error', 'error']],
'next' => [],
'other' => [],
'error' => [],
]),
], 'stop');
$deprecations = [];
set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool {
$deprecations[] = $errstr;

return true;
}, \E_USER_DEPRECATED);
try {
$processConfiguration = $registry->getProcessConfiguration('test.process');
} finally {
restore_error_handler();
}

// Unchanged behaviour until v6.0
self::assertCount(4, $processConfiguration->getTaskConfiguration('first')->getNextTasksConfigurations());
self::assertCount(2, $processConfiguration->getTaskConfiguration('first')->getErrorTasksConfigurations());
self::assertSame([
'Since cleverage/process-bundle 5.7: Listing the task "next" several times in the "outputs" of the task "first" of the process "test.process" is deprecated: it is executed once per occurrence. In v6.0, an exception will be thrown.',
'Since cleverage/process-bundle 5.7: Listing the task "error" several times in the "error_outputs" of the task "first" of the process "test.process" is deprecated: it is executed once per occurrence. In v6.0, an exception will be thrown.',
], $deprecations);
}
}
Loading