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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"require": {
"php": "~8.2.0 || ~8.3.0",
"patchlevel/event-sourcing": "^3.9.0",
"patchlevel/event-sourcing": "^3.10.0",
"symfony/cache": "^6.4.0|^7.0.0",
"symfony/config": "^6.4.0|^7.0.0",
"symfony/console": "^6.4.1|^7.0.1",
Expand Down
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 34 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* command_bus: array{enabled: bool, service: string},
* subscription: array{
* store: array{type: string, service: string|null},
* retry_strategy: array{base_delay: int, delay_factor: int, max_attempts: int},
* retry_strategy?: array{base_delay: int, delay_factor: int, max_attempts: int},
* retry_strategies: array<string, array{type: string, service: string, options: array<string, mixed>}>,
* default_retry_strategy: string,
* catch_up: array{enabled: bool, limit: positive-int|null},
* throw_on_error: array{enabled: bool},
* run_after_aggregate_save: array{
Expand Down Expand Up @@ -182,14 +184,44 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()

->arrayNode('retry_strategy')
->addDefaultsIfNotSet()
->setDeprecated(
'patchlevel/event-sourcing-bundle',
'3.10',
'The "%node%" option is deprecated and will be removed in 4.0. Use "patchlevel_event_sourcing.subscription.retry_strategies" instead.'
)
->children()
->integerNode('base_delay')->defaultValue(5)->end()
->integerNode('delay_factor')->defaultValue(2)->end()
->integerNode('max_attempts')->defaultValue(5)->end()
->end()
->end()

->arrayNode('retry_strategies')
->useAttributeAsKey('name')
->arrayPrototype()
->children()
->enumNode('type')->values(['clock_based', 'no_retry', 'custom'])->end()
->scalarNode('service')->end()
->arrayNode('options')->variablePrototype()->end()->end()
->end()
->end()
->defaultValue([
'default' => [
'type' => 'clock_based',
'options' => [
'base_delay' => 5,
'delay_factor' => 2,
'max_attempts' => 5,
],
],
'no_retry' => [
'type' => 'no_retry',
],
])
->end()

->scalarNode('default_retry_strategy')->defaultValue('default')->end()

->arrayNode('catch_up')
->canBeEnabled()
->addDefaultsIfNotSet()
Expand Down
75 changes: 67 additions & 8 deletions src/DependencyInjection/PatchlevelEventSourcingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
use Patchlevel\EventSourcing\Subscription\Engine\ThrowOnErrorSubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Repository\RunSubscriptionEngineRepositoryManager;
use Patchlevel\EventSourcing\Subscription\RetryStrategy\ClockBasedRetryStrategy;
use Patchlevel\EventSourcing\Subscription\RetryStrategy\NoRetryStrategy;
use Patchlevel\EventSourcing\Subscription\RetryStrategy\RetryStrategy;
use Patchlevel\EventSourcing\Subscription\RetryStrategy\RetryStrategyRepository;
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
use Patchlevel\EventSourcing\Subscription\Store\InMemorySubscriptionStore;
use Patchlevel\EventSourcing\Subscription\Store\SubscriptionStore;
Expand Down Expand Up @@ -335,16 +337,73 @@ static function (ChildDefinition $definition): void {
$container->register(AttributeSubscriberMetadataFactory::class);
$container->setAlias(SubscriberMetadataFactory::class, AttributeSubscriberMetadataFactory::class);

$container->register(ClockBasedRetryStrategy::class)
$strategies = [];

$retryStrategy = $config['subscription']['retry_strategy'] ?? null;

if ($retryStrategy) {
$container->register(ClockBasedRetryStrategy::class)
->setArguments([
new Reference('event_sourcing.clock'),
$retryStrategy['base_delay'],
$retryStrategy['delay_factor'],
$retryStrategy['max_attempts'],
]);

$container->register(NoRetryStrategy::class);

$container
->setAlias(RetryStrategy::class, ClockBasedRetryStrategy::class)
->setDeprecated(
'patchlevel/event-sourcing-bundle',
'3.10',
'The "%alias_id%" alias is deprecated, use "RetryStrategyRepository" instead.',
);

$strategies['default'] = new Reference(RetryStrategy::class);
$strategies['no_retry'] = new Reference(NoRetryStrategy::class);
} else {
foreach ($config['subscription']['retry_strategies'] as $name => $strategyConfig) {
if ($strategyConfig['type'] === 'custom') {
$strategies[$name] = new Reference($strategyConfig['service']);

continue;
}

$id = 'event_sourcing.subscription.retry_strategy.' . $name;

if ($strategyConfig['type'] === 'clock_based') {
$container->register($id, ClockBasedRetryStrategy::class)
->setArguments([
new Reference('event_sourcing.clock'),
$strategyConfig['options']['base_delay'] ?? 5,
$strategyConfig['options']['delay_factor'] ?? 2,
$strategyConfig['options']['max_attempts'] ?? 5,
]);

$strategies[$name] = new Reference($id);

continue;
}

if ($strategyConfig['type'] === 'no_retry') {
$container->register($id, NoRetryStrategy::class);

$strategies[$name] = new Reference($id);

continue;
}

throw new InvalidArgumentException(sprintf('Unknown retry strategy type "%s"', $strategyConfig['type']));
}
}

$container->register(RetryStrategyRepository::class)
->setArguments([
new Reference('event_sourcing.clock'),
$config['subscription']['retry_strategy']['base_delay'],
$config['subscription']['retry_strategy']['delay_factor'],
$config['subscription']['retry_strategy']['max_attempts'],
$strategies,
$config['subscription']['default_retry_strategy'],
]);

$container->setAlias(RetryStrategy::class, ClockBasedRetryStrategy::class);

$container->register(SubscriberHelper::class)
->setArguments([new Reference(SubscriberMetadataFactory::class)]);

Expand Down Expand Up @@ -395,7 +454,7 @@ static function (ChildDefinition $definition): void {
new Reference(Store::class),
new Reference(SubscriptionStore::class),
new Reference(SubscriberAccessorRepository::class),
new Reference(RetryStrategy::class),
new Reference(RetryStrategyRepository::class),
new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE),
])
->addTag('monolog.logger', ['channel' => 'event_sourcing']);
Expand Down
Loading