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
* [#335](https://github.com/cleverage/process-bundle/issues/335) `LineReaderTask` (`line_reader`) and `InputLineReaderTask` (`input_line_reader`): the last line of a file that does not end with a line break is no longer lost. Add tests.
* [#345](https://github.com/cleverage/process-bundle/issues/345) `YamlWriterTask` (`yaml_writer`): a write failure throws a `RuntimeException` instead of a PHP warning (an exception in debug mode only: in production, the path was output as if the file had been written), and the parent directory is created if needed, as for the other writers. Update documentation, add tests.
* [#353](https://github.com/cleverage/process-bundle/issues/353) `cleverage:process:execute`: the process codes and the output format are checked before any process is executed (explicit message for `dump` without `symfony/var-dumper`); the output is printed to STDOUT whatever the verbosity when `--output-format` is given (it required `-vv`); a non-array output that cannot be stored as JSON stream is reported on the error output instead of being silently lost. Update documentation, add tests.
* [#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
-----
Expand Down
2 changes: 2 additions & 0 deletions config/services/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions src/Registry/ProcessConfigurationRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions tests/DependencyInjection/CleverAgeProcessExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions tests/Registry/ProcessConfigurationRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
Loading