Skip to content

Commit 1b1a375

Browse files
authored
Merge pull request #81 from spryker-sdk/feature/frw-10922/master-replace-security-check
FRW-10922 Added retry if service not available.
2 parents 239326d + 7b1aa51 commit 1b1a375

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

src/Checker/OpenSourceVulnerabilitiesChecker/OpenSourceVulnerabilitiesChecker.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ class OpenSourceVulnerabilitiesChecker extends AbstractChecker
7474
*/
7575
protected const ARG_ABANDONED_IGNORE = '--abandoned=ignore';
7676

77+
/**
78+
* @var int
79+
*/
80+
protected const RETRY_ATTEMPTS = 7;
81+
82+
/**
83+
* @var int
84+
*/
85+
protected const RETRY_SLEEP_SECONDS = 3;
86+
7787
/**
7888
* @var \Symfony\Component\Console\Application
7989
*/
@@ -123,7 +133,7 @@ public function check(CheckerInputDataDto $inputData): CheckerResponseDto
123133
return $versionViolation;
124134
}
125135

126-
$rawViolations = $this->runAudit($projectDir);
136+
$rawViolations = $this->runAuditWithRetries($projectDir);
127137

128138
return $this->buildResponseFromRaw($rawViolations);
129139
}
@@ -182,7 +192,7 @@ protected function ensureMinimumComposer(string $projectDir): ?CheckerResponseDt
182192
*
183193
* @return string
184194
*/
185-
protected function runAudit(string $projectDir): string
195+
protected function runAuditWithRetries(string $projectDir): string
186196
{
187197
$args = [
188198
static::SUBCMD_AUDIT,
@@ -191,9 +201,23 @@ protected function runAudit(string $projectDir): string
191201
static::ARG_NO_INTERACTION,
192202
static::ARG_NO_ANSI,
193203
];
194-
[$stdout, $stderr] = $this->runComposerCommand($args, $projectDir);
204+
for ($i = 1; $i <= static::RETRY_ATTEMPTS; $i++) {
205+
[$stdout, $stderr] = $this->runComposerCommand($args, $projectDir);
206+
207+
if ($stdout !== '') {
208+
return $stdout;
209+
}
210+
211+
if ($i < static::RETRY_ATTEMPTS) {
212+
sleep(static::RETRY_SLEEP_SECONDS);
213+
214+
continue;
215+
}
216+
217+
return $stderr;
218+
}
195219

196-
return $stdout !== '' ? $stdout : $stderr;
220+
return '';
197221
}
198222

199223
/**

0 commit comments

Comments
 (0)