Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RunSequentialProcessMessageHandler
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __invoke
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2namespace Apie\ApieBundle\Messenger;
3
4use Apie\Core\BackgroundProcess\BackgroundProcessStatus;
5use Apie\Core\BoundedContext\BoundedContextId;
6use Apie\Core\ContextBuilders\ContextBuilderFactory;
7use Apie\Core\ContextConstants;
8use Apie\Core\Datalayers\ApieDatalayer;
9
10class RunSequentialProcessMessageHandler
11{
12    public function __construct(
13        private readonly ApieDatalayer $apieDatalayer,
14        private readonly ContextBuilderFactory $contextBuilderFactory,
15    ) {
16    }
17
18    public function __invoke(RunSequentialProcessMessage $message): void
19    {
20        $boundedContextId = $message->getBoundedContextId();
21        $process = $this->apieDatalayer->find($message->getProcessId(), $boundedContextId);
22        if ($process->getStatus() !== BackgroundProcessStatus::Active) {
23            return;
24        }
25        $context = [];
26        if ($boundedContextId) {
27            $context[ContextConstants::BOUNDED_CONTEXT_ID] = $boundedContextId->toNative();
28            $context[BoundedContextId::class] = $boundedContextId;
29        }
30            
31        $apieContext = $this->contextBuilderFactory->createGeneralContext($context);
32        $process->runStep($apieContext);
33        $this->apieDatalayer->persistExisting($process, $boundedContextId);
34    }
35}