Skip to content

Commit 0b9cbc8

Browse files
committed
gap detection can be defined in central projection config
1 parent b5f5182 commit 0b9cbc8

File tree

7 files changed

+101
-4
lines changed

7 files changed

+101
-4
lines changed
File renamed without changes.

doc/projection_manager.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ prooph_event_store:
293293
lock_timeout_ms: 1000
294294
trigger_pcntl_dispatch: false
295295
update_lock_threshold: 0
296+
gap_detection:
297+
retry_config: [0, 5, 10, 15, 30, 60, 90]
298+
detection_window: 'P1M'
296299
```
297300

298301
### Tagged service

src/Projection/Options/ProjectionOptionsFactory.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,30 @@
1313

1414
namespace Prooph\Bundle\EventStore\Projection\Options;
1515

16+
use Prooph\EventStore\Pdo\Projection\GapDetection;
17+
use Prooph\EventStore\Pdo\Projection\PdoEventStoreProjector;
18+
1619
final class ProjectionOptionsFactory
1720
{
18-
public static function createProjectionOptions(array $options): ProjectionOptions
21+
public static function createProjectionOptions(array $config): ProjectionOptions
22+
{
23+
\array_walk($config, ['self', 'mapOptions']);
24+
25+
return new ProjectionOptions($config);
26+
}
27+
28+
private static function mapOptions(&$value, string $key): void
1929
{
20-
return new ProjectionOptions($options);
30+
if ($key === PdoEventStoreProjector::OPTION_GAP_DETECTION) {
31+
$value = self::createGapDetection($value);
32+
}
33+
}
34+
35+
private static function createGapDetection(array $config): GapDetection
36+
{
37+
$retryConfig = $config['retry_config'] ?? null;
38+
$detectionWindow = $config['detection_window'] ? new \DateInterval($config['detection_window']) : null;
39+
40+
return new GapDetection($retryConfig, $detectionWindow);
2141
}
2242
}

test/Command/Fixture/config/projections.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ prooph_event_store:
1212
projection: ProophTest\Bundle\EventStore\Command\Fixture\Projection\BlackHoleReadModelProjection
1313
read_model: ProophTest\Bundle\EventStore\Command\Fixture\Projection\BlackHoleReadModel
1414
options:
15-
sleep: 10
15+
cache_size: 666
16+
sleep: 666
17+
persist_block_size: 666
18+
lock_timeout_ms: 666
19+
trigger_pcntl_dispatch: false
20+
update_lock_threshold: 0
21+
gap_detection:
22+
retry_config: [0, 5, 10, 15, 30, 60, 90]
23+
detection_window: 'P1M'
1624

1725
services:
1826
Prooph\EventStore\InMemoryEventStore:

test/DependencyInjection/Compiler/ProjectionOptionsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function it_does_not_allow_tags_without_projection_name(): void
7373
}
7474

7575
/** @test */
76-
public function it_registers_tagged_projection_optionss()
76+
public function it_registers_tagged_projection_options(): void
7777
{
7878
$this->registerProjectionOptions(
7979
'foo.projection_options',

test/DependencyInjection/Fixture/config/yml/projections.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ prooph_event_store:
99
todo_projection:
1010
read_model: 'ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Projection\TodoReadModel'
1111
projection: 'ProophTest\Bundle\EventStore\DependencyInjection\Fixture\Projection\TodoProjection'
12+
options:
13+
cache_size: 1000
14+
sleep: 100000
15+
persist_block_size: 1000
16+
lock_timeout_ms: 1000
17+
trigger_pcntl_dispatch: false
18+
update_lock_threshold: 0
19+
gap_detection:
20+
retry_config: [0, 5, 10, 15, 30, 60, 90]
21+
detection_window: 'P1M'
22+
1223

1324
services:
1425
Prooph\EventStore\InMemoryEventStore:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* This file is part of prooph/event-store-symfony-bundle.
5+
* (c) 2014-2021 Alexander Miertsch <kontakt@codeliner.ws>
6+
* (c) 2015-2021 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ProophTest\Bundle\EventStore\Projection\Options;
15+
16+
use PHPUnit\Framework\TestCase;
17+
use Prooph\Bundle\EventStore\Projection\Options\ProjectionOptions;
18+
use Prooph\Bundle\EventStore\Projection\Options\ProjectionOptionsFactory;
19+
use Prooph\EventStore\Pdo\Projection\GapDetection;
20+
21+
class ProjectionOptionsFactoryTest extends TestCase
22+
{
23+
/**
24+
* @test
25+
*/
26+
public function it_creates_projection_options_instance(): void
27+
{
28+
$config = [
29+
'cache_size' => 1000,
30+
'sleep' => 100000,
31+
'persist_block_size' => 1000,
32+
'lock_timeout_ms' => 1000,
33+
'trigger_pcntl_dispatch' => false,
34+
'update_lock_threshold' => 0,
35+
'gap_detection' => [
36+
'retry_config' => [0, 5, 10, 15, 30],
37+
'detection_window' => 'P5M',
38+
],
39+
];
40+
41+
$options = ProjectionOptionsFactory::createProjectionOptions($config);
42+
43+
$expected = new ProjectionOptions([
44+
'cache_size' => 1000,
45+
'sleep' => 100000,
46+
'persist_block_size' => 1000,
47+
'lock_timeout_ms' => 1000,
48+
'trigger_pcntl_dispatch' => false,
49+
'update_lock_threshold' => 0,
50+
'gap_detection' => new GapDetection([0, 5, 10, 15, 30], new \DateInterval('P5M')),
51+
]);
52+
53+
self::assertEquals($expected, $options);
54+
}
55+
}

0 commit comments

Comments
 (0)