1 | <?php |
||
15 | class RetryParser |
||
16 | { |
||
17 | /** @var TestResultHandlerInterface */ |
||
18 | private $testResultContainer; |
||
19 | |||
20 | /** @var int */ |
||
21 | private $maxRetryCount; |
||
22 | |||
23 | /** @var string */ |
||
24 | private $regexPattern; |
||
25 | |||
26 | /** |
||
27 | * RetryParser constructor. |
||
28 | * @param TestResultHandlerInterface $testResultContainer |
||
29 | * @param int $maxRetryCount |
||
30 | */ |
||
31 | 49 | public function __construct(TestResultHandlerInterface $testResultContainer, int $maxRetryCount = 3) |
|
47 | |||
48 | 44 | public function processWillBeRetried(AbstractParaunitProcess $process, array $logs): bool |
|
49 | { |
||
50 | 44 | if ($process->getRetryCount() >= $this->maxRetryCount) { |
|
51 | 7 | return false; |
|
52 | } |
||
53 | |||
54 | 43 | foreach ($logs as $logItem) { |
|
55 | 43 | if ($this->containsRetriableError($logItem)) { |
|
56 | 10 | $process->markAsToBeRetried(); |
|
57 | 10 | $testResult = new MuteTestResult(); |
|
58 | 10 | $this->testResultContainer->handleTestResult($process, $testResult); |
|
59 | |||
60 | 43 | return true; |
|
61 | } |
||
62 | } |
||
63 | |||
64 | 35 | return false; |
|
65 | } |
||
66 | |||
67 | 43 | private function containsRetriableError(\stdClass $log): bool |
|
68 | { |
||
69 | 43 | return property_exists($log, 'status') |
|
70 | 43 | && $log->status === 'error' |
|
71 | 43 | && preg_match($this->regexPattern, $log->message); |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param string[] $patterns |
||
76 | * @return string |
||
77 | */ |
||
78 | 49 | private function buildRegexPattern(array $patterns): string |
|
84 | } |
||
85 |