From 426b435342cfeadf533a4811854373f36d9e946c Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Mon, 2 Nov 2026 12:04:20 +0100 Subject: [PATCH 1/2] #382 - Deprecate a shared service used by several tasks of a process instead of rejecting it at compile time, reject it in 6.0 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + UPGRADE.md | 14 ++++++++--- docs/03-custom_tasks.md | 2 +- docs/05-good_practices.md | 2 +- .../Compiler/TaskLocatorCompilerPass.php | 13 +++++++--- .../Compiler/TaskLocatorCompilerPassTest.php | 25 ++++++++++++++++--- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0da39796..e0da52c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Latest * [#370](https://github.com/cleverage/process-bundle/issues/370) `RulesTransformer` (`rules`): the result of a `condition` is cast to `bool`, so a condition returning an `int` (`preg_match()`), a string, `null` or any other non-boolean value (a single variable) no longer throws a `TypeError`: the rule matches if the result is truthy. Update documentation, add tests. * [#372](https://github.com/cleverage/process-bundle/issues/372) `ProcessConfigurationRegistry`: an unknown task in the `outputs` or `error_outputs` of a task, or in the `entry_point` or `end_point` of a process, throws an `InvalidProcessConfigurationException` naming the process, the task and the key holding the reference, instead of a `MissingTaskConfigurationException` (`No task configuration with code : `). A process whose configuration is not valid is left out of `getProcessConfigurations()` (`cleverage:process:list`, lists of the UI) with an error log on the `cleverage_process` channel, instead of making every listing fail; getting or executing this process still throws. Update documentation, add tests. * [#373](https://github.com/cleverage/process-bundle/issues/373) `ProcessManager`: the tasks are finalized (`FinalizableTaskInterface::finalize()`) when the process fails too, so that a long-running worker (Messenger, UI bundle) no longer keeps the resources of a failed process open (files of the CSV, JSON stream and XML tasks, cursor of `doctrine_database_reader` blocking the next queries with MySQL unbuffered queries). Only the initialized tasks are finalized, each one once; a finalization failure is logged as critical and the process fails with its original exception. `StatCounterTask` (`stat_counter`) logs its count when the process fails too. Update documentation, add tests. +* [#382](https://github.com/cleverage/process-bundle/issues/382) A shared service referenced by several tasks of the same process is deprecated instead of being rejected when the container is compiled (5.5, #339): this configuration worked before 5.5, all these tasks running with the same instance. The deprecation names the service, the tasks and the process; it will be rejected in 6.0. Declare the task services with `shared: false`. Update documentation, update tests. v5.5 ----- diff --git a/UPGRADE.md b/UPGRADE.md index f7a4208a..72f7b281 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -3,7 +3,7 @@ Upgrade Guide ## v5.6 -One deprecation, and some behaviours change: check the points below. +Two deprecations, and some behaviours change: check the points below. ### Recursive process execution @@ -17,6 +17,12 @@ Iterate with an iterable task (e.g. a reader or `constant_iterable_output` follo recursing, or use the `process_launcher` task, which runs the process in a separate PHP process. Executing the same sub-process several times in a row is not concerned. +### Shared task services + +A shared service referenced by several tasks of the same process is no longer rejected when the container is compiled +(5.5): it is deprecated since 5.5.1, and will be rejected in v6.0. The deprecation names the service, the tasks and the +process: declare the service with `shared: false` (see v5.5 below). + ### Finalization of the tasks when the process fails `FinalizableTaskInterface::finalize()` is now also called when the process fails, on every task that has been @@ -33,9 +39,9 @@ No deprecation in this version. Some behaviours change: check the points below. ### Shared task services A shared service referenced by several tasks of the same process is rejected when the container is compiled -(`InvalidArgumentException` naming the service, the tasks and the process): all these tasks ran with the same instance, -initialized with the options of each task in turn. Declare your task services with `shared: false`, as the -autoconfiguration of `TaskInterface` does since 5.4: +(`InvalidArgumentException` naming the service, the tasks and the process; deprecated instead since 5.5.1, see above): +all these tasks ran with the same instance, initialized with the options of each task in turn. Declare your task +services with `shared: false`, as the autoconfiguration of `TaskInterface` does since 5.4: ```yaml # config/services.yaml diff --git a/docs/03-custom_tasks.md b/docs/03-custom_tasks.md index 72bca29a..7742d621 100644 --- a/docs/03-custom_tasks.md +++ b/docs/03-custom_tasks.md @@ -21,7 +21,7 @@ Most of the time you don't want a task declared in a process to share some data same service, or even with another instance of your process. Since a task is a service, by default, Symfony will only create one instance (keeping values in every attribute of your class). With `shared: false`, a new instance is created each time a task configuration is initialized. A shared service referenced by several tasks of the same process is -rejected when the container is compiled. +deprecated (a deprecation is triggered when the container is compiled) and will be rejected in v6.0. With autoconfiguration (`autoconfigure: true`, set in the `_defaults` of the Symfony skeleton), the bundle applies these settings to every service implementing `TaskInterface`: `shared: false` and a `monolog.logger` tag on the diff --git a/docs/05-good_practices.md b/docs/05-good_practices.md index ebe20410..b82f710b 100644 --- a/docs/05-good_practices.md +++ b/docs/05-good_practices.md @@ -19,7 +19,7 @@ in several places, declare it once as a [generic transformer](reference/03-gener Task services should be `shared: false`: a task often keeps state in its properties (an open file, a buffer, a counter...). A shared service would share this state between two tasks using the same service -in a process (this is rejected when the container is compiled), or between two executions of a process in the same PHP +in a process (deprecated, rejected in v6.0), or between two executions of a process in the same PHP process (sub-processes, workers, tests). See [service declaration](03-custom_tasks.md#service-declaration). ## Split big workflows into small processes diff --git a/src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php b/src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php index 3d6ba77a..1c26f5ee 100644 --- a/src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php +++ b/src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php @@ -60,8 +60,8 @@ public function process(ContainerBuilder $container): void } /** - * A shared service referenced by several tasks of a process would run all of them with the same instance: the - * options of the last initialization would apply to every task, and their states would be mixed. + * A shared service referenced by several tasks of a process runs all of them with the same instance: the options of + * the last initialization apply to every task, and their states are mixed. Deprecated, rejected in v6.0. * * @param array> $taskCodesByService */ @@ -69,7 +69,14 @@ private function checkSharedServices(ContainerBuilder $container, string $proces { foreach ($taskCodesByService as $id => $taskCodes) { if (\count($taskCodes) > 1 && $container->findDefinition($id)->isShared()) { - throw new InvalidArgumentException(\sprintf('The service "%s" is used by the tasks "%s" of the process "%s", but it is shared: all these tasks would run with the same instance (and the options of one of them). Declare the service with "shared: false".', $id, implode('", "', $taskCodes), $processCode)); + trigger_deprecation( + 'cleverage/process-bundle', + '5.5.1', + 'The service "%s" is used by the tasks "%s" of the process "%s", but it is shared: all these tasks run with the same instance (and the options of one of them). Declare the service with "shared: false". Shared services used by several tasks of a process are deprecated, they will be rejected in v6.0.', + $id, + implode('", "', $taskCodes), + $processCode + ); } } } diff --git a/tests/DependencyInjection/Compiler/TaskLocatorCompilerPassTest.php b/tests/DependencyInjection/Compiler/TaskLocatorCompilerPassTest.php index a5a10342..3eec2b83 100644 --- a/tests/DependencyInjection/Compiler/TaskLocatorCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/TaskLocatorCompilerPassTest.php @@ -134,15 +134,32 @@ public function testInvalidTaskCodeAttributeThrows(): void (new TaskLocatorCompilerPass())->process($container); } - public function testSharedServiceUsedBySeveralTasksOfAProcessThrows(): void + public function testSharedServiceUsedBySeveralTasksOfAProcessIsDeprecated(): void { $container = $this->createContainerWithTasks(['test.process' => ['first' => 'app_task', 'second' => 'app_task']]); $container->setDefinition('app.task', (new Definition(DummyTask::class))->addTag('cleverage.task', ['code' => 'app_task'])); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The service "app.task" is used by the tasks "first", "second" of the process "test.process", but it is shared: all these tasks would run with the same instance (and the options of one of them). Declare the service with "shared: false".'); + $deprecations = []; + set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool { + $deprecations[] = $errstr; - (new TaskLocatorCompilerPass())->process($container); + return true; + }, \E_USER_DEPRECATED); + try { + (new TaskLocatorCompilerPass())->process($container); + } finally { + restore_error_handler(); + } + + self::assertSame([ + 'Since cleverage/process-bundle 5.5.1: The service "app.task" is used by the tasks "first", "second" of the process "test.process", but it is shared: all these tasks run with the same instance (and the options of one of them). Declare the service with "shared: false". Shared services used by several tasks of a process are deprecated, they will be rejected in v6.0.', + ], $deprecations); + // The service is still available to the tasks, as before 5.5 + $locatorReference = $container->getDefinition('cleverage_process.registry.task')->getArgument(0); + self::assertInstanceOf(Reference::class, $locatorReference); + $services = $container->getDefinition((string) $locatorReference)->getArgument(0); + self::assertIsArray($services); + self::assertSame(['app.task'], array_keys($services)); } public function testNonSharedServiceCanBeUsedBySeveralTasksOfAProcess(): void From 463b08e42805166843e98051a86c403d2c974db2 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Mon, 2 Nov 2026 12:21:52 +0100 Subject: [PATCH 2/2] #382 - Deprecation since 5.6, the next release Co-Authored-By: Claude Opus 5.5 --- UPGRADE.md | 4 ++-- src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php | 2 +- .../Compiler/TaskLocatorCompilerPassTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 72f7b281..0ddbb8bd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -20,7 +20,7 @@ sub-process several times in a row is not concerned. ### Shared task services A shared service referenced by several tasks of the same process is no longer rejected when the container is compiled -(5.5): it is deprecated since 5.5.1, and will be rejected in v6.0. The deprecation names the service, the tasks and the +(5.5): it is deprecated since 5.6, and will be rejected in v6.0. The deprecation names the service, the tasks and the process: declare the service with `shared: false` (see v5.5 below). ### Finalization of the tasks when the process fails @@ -39,7 +39,7 @@ No deprecation in this version. Some behaviours change: check the points below. ### Shared task services A shared service referenced by several tasks of the same process is rejected when the container is compiled -(`InvalidArgumentException` naming the service, the tasks and the process; deprecated instead since 5.5.1, see above): +(`InvalidArgumentException` naming the service, the tasks and the process; deprecated instead since 5.6, see above): all these tasks ran with the same instance, initialized with the options of each task in turn. Declare your task services with `shared: false`, as the autoconfiguration of `TaskInterface` does since 5.4: diff --git a/src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php b/src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php index 1c26f5ee..8cadacb2 100644 --- a/src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php +++ b/src/DependencyInjection/Compiler/TaskLocatorCompilerPass.php @@ -71,7 +71,7 @@ private function checkSharedServices(ContainerBuilder $container, string $proces if (\count($taskCodes) > 1 && $container->findDefinition($id)->isShared()) { trigger_deprecation( 'cleverage/process-bundle', - '5.5.1', + '5.6', 'The service "%s" is used by the tasks "%s" of the process "%s", but it is shared: all these tasks run with the same instance (and the options of one of them). Declare the service with "shared: false". Shared services used by several tasks of a process are deprecated, they will be rejected in v6.0.', $id, implode('", "', $taskCodes), diff --git a/tests/DependencyInjection/Compiler/TaskLocatorCompilerPassTest.php b/tests/DependencyInjection/Compiler/TaskLocatorCompilerPassTest.php index 3eec2b83..a2f2937f 100644 --- a/tests/DependencyInjection/Compiler/TaskLocatorCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/TaskLocatorCompilerPassTest.php @@ -152,7 +152,7 @@ public function testSharedServiceUsedBySeveralTasksOfAProcessIsDeprecated(): voi } self::assertSame([ - 'Since cleverage/process-bundle 5.5.1: The service "app.task" is used by the tasks "first", "second" of the process "test.process", but it is shared: all these tasks run with the same instance (and the options of one of them). Declare the service with "shared: false". Shared services used by several tasks of a process are deprecated, they will be rejected in v6.0.', + 'Since cleverage/process-bundle 5.6: The service "app.task" is used by the tasks "first", "second" of the process "test.process", but it is shared: all these tasks run with the same instance (and the options of one of them). Declare the service with "shared: false". Shared services used by several tasks of a process are deprecated, they will be rejected in v6.0.', ], $deprecations); // The service is still available to the tasks, as before 5.5 $locatorReference = $container->getDefinition('cleverage_process.registry.task')->getArgument(0);