From f0f9e24df47884089fb7319a5d9c5f1b429763d7 Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Thu, 22 Oct 2026 18:43:55 +0200 Subject: [PATCH] #355 - ProcessConfigurationRegistry::reset() (kernel.reset): release the task instances and states of the last executions between two messages of a worker. Add tests. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 3 ++ config/services/registry.yaml | 2 + src/Registry/ProcessConfigurationRegistry.php | 9 ++++ .../CleverAgeProcessExtensionTest.php | 5 +++ .../ProcessConfigurationRegistryTest.php | 41 +++++++++++++++++++ 5 files changed, 60 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b33c604..448af882 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Latest ------ +## Fixes +* [#355](https://github.com/cleverage/process-bundle/issues/355) `ProcessConfigurationRegistry::reset()`, tagged `kernel.reset`: a long-running worker (Messenger, UI bundle) releases the resolved process configurations, with the task instances and states (inputs, outputs, aggregated data) of their last execution, between two messages. Add tests. + v5.4.1 ----- diff --git a/config/services/registry.yaml b/config/services/registry.yaml index 73c10514..e476e992 100644 --- a/config/services/registry.yaml +++ b/config/services/registry.yaml @@ -6,6 +6,8 @@ services: - ~ - ~ - ~ + tags: + - { name: kernel.reset, method: reset } CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry: alias: cleverage_process.registry.process_configuration CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistryInterface: diff --git a/src/Registry/ProcessConfigurationRegistry.php b/src/Registry/ProcessConfigurationRegistry.php index cca08a61..73b067b3 100644 --- a/src/Registry/ProcessConfigurationRegistry.php +++ b/src/Registry/ProcessConfigurationRegistry.php @@ -65,6 +65,15 @@ public function getProcessConfigurations(): array return $this->processConfigurations; } + /** + * Forgets the resolved configurations, with the task instances and states of their last execution, e.g. between + * two messages of a long-running worker: they are resolved again when needed. + */ + public function reset(): void + { + $this->processConfigurations = []; + } + public function hasProcessConfiguration(string $processCode): bool { return \array_key_exists($processCode, $this->rawConfiguration); diff --git a/tests/DependencyInjection/CleverAgeProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeProcessExtensionTest.php index f85db280..e2255ddb 100644 --- a/tests/DependencyInjection/CleverAgeProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeProcessExtensionTest.php @@ -212,6 +212,11 @@ public function testTheProcessManagerIsResetBetweenExecutions(): void [['method' => 'reset']], $container->getDefinition('cleverage_process.manager.process')->getTag('kernel.reset') ); + // The task instances and states of the last executions are released + self::assertSame( + [['method' => 'reset']], + $container->getDefinition('cleverage_process.registry.process_configuration')->getTag('kernel.reset') + ); } public function testTheDataQueueListenerIsDeprecated(): void diff --git a/tests/Registry/ProcessConfigurationRegistryTest.php b/tests/Registry/ProcessConfigurationRegistryTest.php index e6eceb7e..50e09f96 100644 --- a/tests/Registry/ProcessConfigurationRegistryTest.php +++ b/tests/Registry/ProcessConfigurationRegistryTest.php @@ -13,11 +13,16 @@ namespace CleverAge\ProcessBundle\Tests\Registry; +use CleverAge\ProcessBundle\Configuration\ProcessConfiguration; +use CleverAge\ProcessBundle\Configuration\TaskConfiguration; use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; #[CoversClass(ProcessConfigurationRegistry::class)] +#[UsesClass(ProcessConfiguration::class)] +#[UsesClass(TaskConfiguration::class)] class ProcessConfigurationRegistryTest extends TestCase { public function testTaskCodeNotResolvedAtCompileTimeThrows(): void @@ -42,4 +47,40 @@ public function testTaskCodeNotResolvedAtCompileTimeThrows(): void $registry->getProcessConfiguration('test.process'); } + + public function testResetForgetsTheResolvedConfigurations(): void + { + $registry = new ProcessConfigurationRegistry([ + 'test.process' => [ + 'options' => [], + 'entry_point' => null, + 'end_point' => null, + 'description' => '', + 'help' => '', + 'public' => true, + 'tasks' => [ + 'my_task' => [ + 'service' => '@app.task', + 'options' => [], + 'description' => '', + 'help' => '', + 'outputs' => [], + 'errors' => [], + 'error_outputs' => [], + 'error_strategy' => null, + 'log_level' => null, + ], + ], + ], + ], 'stop'); + $configuration = $registry->getProcessConfiguration('test.process'); + self::assertSame($configuration, $registry->getProcessConfiguration('test.process')); + + $registry->reset(); + + // Resolved again: the task instances and states of the previous executions are released + $resolvedAgain = $registry->getProcessConfiguration('test.process'); + self::assertNotSame($configuration, $resolvedAgain); + self::assertSame('test.process', $resolvedAgain->getCode()); + } }