Skip to content

Commit 0502936

Browse files
authored
Stats interceptor async -> sync (#31)
1 parent 290dc03 commit 0502936

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/Events/EventHandlersMap.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ class EventHandlersMap
1717

1818
private StatisticsSenderHandler $statisticsSenderHandler;
1919

20-
private RelatedUsersStatisticsInterceptor $relatedUsersStatisticsInterceptor;
21-
2220
private array $map;
2321

2422
public function __construct(
2523
AddUserToBranchHandler $addUserToBranchHandler,
26-
StatisticsSenderHandler $statisticsSenderHandler,
27-
RelatedUsersStatisticsInterceptor $relatedUsersStatisticsInterceptor
24+
StatisticsSenderHandler $statisticsSenderHandler
2825
) {
2926
$this->addUserToBranchHandler = $addUserToBranchHandler;
3027
$this->statisticsSenderHandler = $statisticsSenderHandler;
31-
$this->relatedUsersStatisticsInterceptor = $relatedUsersStatisticsInterceptor;
3228
$this->map = $this->getInitialMap();
3329
}
3430

@@ -74,7 +70,6 @@ private function getInitialMap(): array
7470
],
7571
SendEventTask::class => [
7672
$this->statisticsSenderHandler,
77-
$this->relatedUsersStatisticsInterceptor,
7873
],
7974
];
8075
}

src/Manager/StatisticsManager.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Abrouter\Client\Events\EventDispatcher;
88
use Abrouter\Client\DTO\EventDTOInterface;
9+
use Abrouter\Client\Events\Handlers\RelatedUsersStatisticsInterceptor;
910
use Abrouter\Client\Services\ExperimentsParallelRun\ParallelRunSwitch;
1011
use Abrouter\Client\Services\Statistics\SendEventTask;
1112

@@ -15,21 +16,34 @@ class StatisticsManager
1516

1617
private ParallelRunSwitch $parallelRunSwitch;
1718

19+
private RelatedUsersStatisticsInterceptor $relatedUsersStatisticsInterceptor;
20+
1821
/**
1922
* @param EventDispatcher $eventDispatcher
2023
* @param ParallelRunSwitch $parallelRunSwitch
24+
* @param RelatedUsersStatisticsInterceptor $relatedUsersStatisticsInterceptor
2125
*/
22-
public function __construct(EventDispatcher $eventDispatcher, ParallelRunSwitch $parallelRunSwitch)
23-
{
26+
public function __construct(
27+
EventDispatcher $eventDispatcher,
28+
ParallelRunSwitch $parallelRunSwitch,
29+
RelatedUsersStatisticsInterceptor $relatedUsersStatisticsInterceptor
30+
) {
2431
$this->eventDispatcher = $eventDispatcher;
2532
$this->parallelRunSwitch = $parallelRunSwitch;
33+
$this->relatedUsersStatisticsInterceptor = $relatedUsersStatisticsInterceptor;
2634
}
2735

2836
public function sendEvent(EventDTOInterface $eventDTO): void
2937
{
38+
$task = new SendEventTask($eventDTO);
39+
$isParallelRunningEnabled = $this->parallelRunSwitch->isEnabled();
40+
if ($isParallelRunningEnabled) {
41+
$this->relatedUsersStatisticsInterceptor->handle($task);
42+
}
43+
3044
$this->eventDispatcher->dispatch(
31-
new SendEventTask($eventDTO),
32-
$this->parallelRunSwitch->isEnabled()
45+
$task,
46+
$isParallelRunningEnabled
3347
);
3448
}
3549
}

0 commit comments

Comments
 (0)