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 @@ -12,6 +12,7 @@ Latest
* [#292](https://github.com/cleverage/process-bundle/issues/292) Remove the fallbacks of the task registry on the service container, deprecated since 5.4 (#275): the `$container` argument of the `ProcessManager` constructor is removed and its `TaskRegistryInterface $taskRegistry` argument is required, before `$stopCheckers`; `ProcessHelpCommand` only accepts a `TaskRegistryInterface`; `TaskRegistry` only fetches the tasks from its service locator (a task of a process configuration unknown when the container is compiled is not found). The `service` key of the task configurations is removed, use `task: <code>`. The tasks and transformers of the bundle, and the tasks of the application autoconfigured with `TaskInterface`, are private; `PublicTaskDeprecationCompilerPass` is removed (see `UPGRADE.md`). Update documentation and tests.
* [#292](https://github.com/cleverage/process-bundle/issues/292) Reject the process configuration errors deprecated during v5: the `errors` task configuration key is removed (use `error_outputs`), with `TaskConfiguration::getErrors()` and `$logErrors`; an unknown `error_strategy` (#310) and an unknown task reference (#426) fail the container compilation; a task listed several times in the `outputs` / `error_outputs` of a task throws an `InvalidProcessConfigurationException` (#414); a shared service used by several tasks of a process fails the container compilation (#382). The former names of the codes with a dash, with underscores, are no longer found (#412, #475): processes, tasks, generic transformers, transformer codes and contextual options of the generic transformers; `DeprecatedCodeAliases` and the second argument of the `TransformerRegistry` constructor are removed (see `UPGRADE.md`). Update documentation and tests.
* [#292](https://github.com/cleverage/process-bundle/issues/292) Remove the classes, methods and options deprecated during v5: `ProcessState::getReturnCode()` / `setReturnCode()` (#503), the `cleverage_process.event_listener.data_queue` service and `DataQueueEventListener` (#311), `CheckSerializerCompilerPass`, the `KernelInterface` argument and the `$kernel` / `$logDir` properties of `CommandRunnerTask`, `ProcessLauncherTask` and `SubprocessInstance` (#318), the `process_options` option of the `process_launcher` task (see `UPGRADE.md`). Update documentation and tests.
* [#292](https://github.com/cleverage/process-bundle/issues/292) Apply the behaviours announced by the deprecations of v5: an exception thrown by the `initialize()` of a task makes the process fail before any task is executed, with a `ProcessFailedException` (#222); the `event_dispatcher` task no longer dispatches its event under the class name of the event too when `event_name` is set (#189); a target property of an array destination that is neither a simple property name nor an index notation (`address.city`) throws an `UnexpectedValueException` in the `mapping` transformer (#117); the `additional_parameters` option of the `callback` transformer is removed, use `right_parameters`; a negative `flush_every` of the `counter` task is rejected (#491) (see `UPGRADE.md`). Update documentation and tests.

## Changes
* [#428](https://github.com/cleverage/process-bundle/issues/428) Tests on PHPUnit 12.5 and 13 (PHPUnit 10 and 11 dropped), with the lowest dependencies on PHP 8.3 and 8.5.
Expand Down
18 changes: 18 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ The former names of the codes with a dash, with underscores instead of dashes, a
- the `process_options` option of the `process_launcher` task is removed (deprecated, a non-empty value already threw):
remove it from your process configurations, an `UndefinedOptionsException` is thrown otherwise.

### Behaviours announced by the deprecations

- an exception thrown by the `initialize()` method of a task (e.g. options that cannot be resolved) makes the process
fail before any task is executed, with a `ProcessFailedException` whose previous exception is the one thrown (it was
logged, deprecated since 5.1, and the process only failed when the task was first executed, or ended normally when it
was never reached): fix the configuration of the task;
- the `event_dispatcher` task with an `event_name` no longer dispatches its event under the
`CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent` class name too (deprecated since 5.1): its listeners must
listen to the `event_name`;
- in the `mapping` transformer, a target property of an array destination that is neither a simple property name nor
an index notation (e.g. `address.city`, `address[city]`) throws an `UnexpectedValueException` (it was set as a
literal key, deprecated since 5.2): write `[address.city]` to keep the literal key, or `[address][city]` for a nested
array;
- the `additional_parameters` option of the `callback` transformer is removed (deprecated since 2.0.4): rename it
`right_parameters`, an `UndefinedOptionsException` is thrown otherwise;
- a negative `flush_every` option of the `counter` task is rejected with an `InvalidOptionsException` (it worked as
its absolute value, deprecated since 5.10): use a positive integer.

## v5.10

### Stop strategy and error branch ending on a stop
Expand Down
18 changes: 7 additions & 11 deletions docs/02-task_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,11 @@ and prepare anything needed for the main execution of the task. All tasks of a p
they are configured, before any execution.

This is especially useful (for example) when the process starts with heavy tasks before actually uploading a file, to
detect a problem early. Note however that an exception thrown by `initialize` does not abort the process: it is logged
(`critical` level, on the `cleverage_process_task` channel) and the task state is flagged as stopped, then the process
goes on. The failure only surfaces when the task is first reached: for [configurable tasks](#configurable-tasks-and-options),
the options are resolved again and the process fails at that point (upstream tasks may already have run); for other
tasks, the branch stops after this first execution. If the task is never reached, the process ends normally.

This behaviour is deprecated since 5.1 (an `E_USER_DEPRECATED` error is triggered for each initialization failure): in
v6.0, an initialization failure will make the process fail before any task is executed.
detect a problem early. An exception thrown by `initialize` is logged (`critical` level, on the
`cleverage_process_task` channel) and makes the process fail before any task is executed, with a
`ProcessFailedException` (its previous exception is the one thrown by `initialize`), even when the task would never be
reached. Before v6.0, the process went on: it only failed when the task was first executed. A task whose `initialize`
has failed is not finalized: release what it has already opened (file, connection...) before throwing.

## Configurable tasks and options

Expand All @@ -138,9 +135,8 @@ behavior. Options are a way to configure a task.
Configurable tasks extend `CleverAge\ProcessBundle\Model\AbstractConfigurableTask`. It is an initializable task that
relies on [Symfony's OptionsResolver Component](https://symfony.com/doc/current/components/options_resolver.html):
- you define the options in the abstract `configureOptions(OptionsResolver $resolver)` method
- options are resolved (and validated) during `initialize`, so a misconfigured task is logged as critical before any
execution; the process itself only fails when the task is first executed (see
[initializable tasks](#initializable-tasks))
- options are resolved (and validated) during `initialize`, so a misconfigured task makes the process fail before any
execution (see [initializable tasks](#initializable-tasks))
- the options are read from the task `options` configuration, after replacing the `{{ key }}` placeholders with the
process context values (see [contextual values](01-quick_start.md#contextual-values))
- in `execute`, use `$this->getOptions($state)` or `$this->getOption($state, 'code')` to read the resolved options
Expand Down
6 changes: 2 additions & 4 deletions docs/03-custom_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ Based on [Symfony's OptionsResolver Component](https://symfony.com/doc/current/c
abstract class allows you to implement its `configureOptions` method to add your requirements, default values and
normalizers. Options are resolved (once) during the task initialization, and can be read with `getOptions($state)` or
`getOption($state, $code)`. If you override `getOptions()`, it must return an `array` (it was typed `?array` before
v6.0). If the resolution fails during initialization, the error is logged and the options are resolved again (failing
the process) when the task is first executed. Going on with the process after an initialization failure is deprecated
since 5.1: in v6.0, the process will fail before any task is executed (see
[initializable tasks](02-task_types.md#initializable-tasks)).
v6.0). If the resolution fails during initialization, the error is logged and the process fails before any task is
executed (see [initializable tasks](02-task_types.md#initializable-tasks)).

```php
namespace App\Task;
Expand Down
8 changes: 4 additions & 4 deletions docs/04-advanced_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ When a process is executed (with the `cleverage:process:execute` command or with
the *main branch*, the group of connected tasks that is actually executed (see [orphan tasks](#orphan-tasks))
3. **initializes** every task, in the order they are configured: the service is fetched from the task registry and
`initialize` is called on [initializable tasks](02-task_types.md#initializable-tasks) (for configurable tasks, this is
where options are validated). An exception thrown by `initialize` is logged as critical and flags the task as
stopped, but does not abort the process: it only fails when this task is first executed. This is deprecated since 5.1
(an `E_USER_DEPRECATED` error is triggered): in v6.0, the process will fail at this step, before any task is executed
where options are validated). An exception thrown by `initialize` is logged as critical and makes the process fail
at this step, before any task is executed (with a `ProcessFailedException`); the tasks already initialized are
finalized (see [finalizable tasks](02-task_types.md#finalizable-tasks))
4. gives the process input to the `entry_point` task, if one is defined (otherwise the input is ignored and a warning is
logged)
5. **resolves** the tasks of the main branch (see below)
Expand Down Expand Up @@ -112,7 +112,7 @@ Only one group of connected tasks, the *main branch*, is executed. It is the gro
or the `end_point` task if there is no entry point, or else the first configured task. Tasks that are not connected
to it (not referenced in any `outputs` or `error_outputs` of the main branch) are never executed: a warning
`Task '<code>' is unreachable` is logged for each of them. They are still initialized and finalized, like every task of
the process (so a misconfigured orphan task still logs its initialization error). The `cleverage:process:help` command
the process (so a misconfigured orphan task makes the process fail at the initialization). The `cleverage:process:help` command
only displays the main branch.

### Errors and skips
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/tasks/counter_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ Notes
[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.
first execution (`Modulo by zero`). A negative value is rejected the same way since v6.0: it worked as its absolute
value (`-3` as `3`), deprecated since 5.10.
7 changes: 3 additions & 4 deletions docs/reference/tasks/event_dispatcher_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public function onDataQueue(EventDispatcherTaskEvent $event): void
`CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent`. Every `EventDispatcherTask` without `event_name` then
triggers the same listeners.

**Deprecated since 5.1 (deprecation notice), removed in v6.0**: from v4.0 to v5.0, the `event_name` option was ignored and the event was
always dispatched under its class name. To preserve backward compatibility, when `event_name` is set (and differs from the
event class name) and listeners subscribe to `CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent`, the event is also
dispatched under its class name and an `E_USER_DEPRECATED` error is triggered. In v6.0, listen to the configured
Since v6.0, an event dispatched under its `event_name` is no longer dispatched under its class name too: the listeners
of `CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent` are only called by the tasks without `event_name`. From
v4.0 to v5.x, they were also called (deprecated since 5.1) when `event_name` was set: listen to the configured
`event_name` instead, or remove the `event_name` option.
2 changes: 1 addition & 1 deletion docs/reference/tasks/folder_browser_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Options

| Code | Type | Required | Default | Description |
|-------------------|-----------------------|:--------:|-----------|----------------------------------------------------------------------------------------------------------------|
| `folder_path` | `string` | **X** | | Path of the folder to browse. Must be an existing readable directory (checked at initialization; with process-bundle v5, the process fails when the task is first executed, see [initializable tasks](../../02-task_types.md#initializable-tasks)) |
| `folder_path` | `string` | **X** | | Path of the folder to browse. Must be an existing readable directory (checked at initialization: the process fails before any task is executed, see [initializable tasks](../../02-task_types.md#initializable-tasks)) |
| `name_pattern` | `string\|array\|null` | | `null` | Restrict files by name using a pattern (glob, regexp or string) or an array of patterns (see `Finder::name()`) |
| `empty_log_level` | `string` | | `warning` | Log level used when no file is found, one of the `Psr\Log\LogLevel` constants |

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/tasks/process_executor_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Notes
`stop` (default), the parent process fails too; with `skip`, the parent process goes on with the next input (the
input is sent to the `error_outputs` of the task, if any).
* The `process` option is checked when the task is initialized: with an unknown process, the initialization fails, the
error is logged and, with process-bundle v5, the parent process fails when the task is first executed (see
error is logged and the parent process fails before any of its tasks is executed (see
[initializable tasks](../../02-task_types.md#initializable-tasks)).
* Executing a process while it is already running, by itself or through its sub-processes (`A → B → A`), is
deprecated since 5.6 and will throw an exception in 6.0: a process has only one set of task instances and states,
Expand Down
9 changes: 3 additions & 6 deletions docs/reference/tasks/stop_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ file does not exist. Unlike [DieTask](die_task.md), the stop is handled by the p
* `cleverage:process:execute` exits with code 0, and the task running a sub-process
([ProcessExecutorTask](process_executor_task.md)) goes on.

A process that has already failed (e.g. a task whose initialization failed, see the
[initializable tasks](../../02-task_types.md)) stays **failed**: the `StopTask` still stops the flow of the
tasks, but it does not turn the failure into a stop.

To stop a process because of an error, let the error fail the process instead (error strategy `stop`). A `StopTask` in
the error branch of a task with the `stop` strategy does not turn its failure into a stop: the process fails.
To stop a process because of an error, let the error fail the process instead (error strategy `stop`). A process that
has already failed stays **failed**: a `StopTask` in the error branch of a task with the `stop` strategy still stops the
flow of the tasks, but it does not turn the failure into a stop.

Task reference
--------------
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/tasks/yaml_reader_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Options

| Code | Type | Required | Default | Description |
|-------------|----------|:--------:|---------|----------------------------------------------------------------------------------------------------------------------|
| `file_path` | `string` | **X** | | Path of the YAML file to read. An `UnexpectedValueException` is thrown at initialization if the file does not exist (with process-bundle v5, the process fails when the task is first executed, see [initializable tasks](../../02-task_types.md#initializable-tasks)) |
| `file_path` | `string` | **X** | | Path of the YAML file to read. An `UnexpectedValueException` is thrown at initialization if the file does not exist (the process fails before any task is executed, see [initializable tasks](../../02-task_types.md#initializable-tasks)) |

Examples
--------
Expand Down
1 change: 0 additions & 1 deletion docs/reference/transformers/callback_transformer.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Options
| `callback` | `string\|array` | **X** | | A valid PHP callable (e.g. `mb_strtoupper`, `['App\MyClass', 'myStaticMethod']`), checked with `is_callable` |
| `left_parameters` | `array` | | `[]` | Parameters passed before the value |
| `right_parameters` | `array` | | `[]` | Parameters passed after the value |
| `additional_parameters` | `array` | | `[]` | **Deprecated**: use `right_parameters` instead. Only used when `right_parameters` is empty |

Examples
--------
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/transformers/mapping_transformer.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ Notes
`NoSuchPropertyException` is thrown (`Cannot read the property "[name]" of a value of type "null": the input must be
an array or an object.`).
* When a sub-transformer fails, the thrown `TransformerException` reports the target property.
* On an array destination, a target property that is not an index notation is added as a literal key: a simple
property name (e.g. `name`) gives the `name` key. Doing so with a nested path (e.g. `address.city`, `address[city]`)
is deprecated and will throw an `UnexpectedValueException` in v6.0: use `[address.city]` to keep a literal key, or
`[address][city]` to write in a nested array.
* On an array destination, a simple target property name (e.g. `name`) is added as the `name` key. Another target
property that is not an index notation (a nested path, e.g. `address.city`, `address[city]`) throws an
`UnexpectedValueException` since v6.0 (it was added as a literal key, deprecated since 5.2): use `[address.city]` to
keep a literal key, or `[address][city]` to write in a nested array.
* A missing property of a `\stdClass` destination is added only for a simple target property name (e.g. `name`): a
nested path (e.g. `address.city`) or an index notation (e.g. `[name]`) that is not writable throws an
`UnexpectedValueException` (`Property '...' is not writable`), as for any other object.
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ProcessFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace CleverAge\ProcessBundle\Exception;

/**
* Thrown when a process is stopped by a task error (error strategy "stop").
* Thrown when a process is stopped by a task error (error strategy "stop"), or by the initialization failure of a task.
*
* The original exception is available with getPrevious().
*/
Expand Down
Loading