Implemented retry logic for HTTP requests in Repositories

This commit is contained in:
Netkas 2023-10-04 15:12:56 -04:00
parent cf7e1aa107
commit 8ce6c68d77
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
4 changed files with 55 additions and 7 deletions

View file

@ -474,11 +474,23 @@
*/
private static function processHttpResponse(CurlHandle $curl, string $group, string $project): array
{
$response = curl_exec($curl);
$retry_count = 0;
$response = false;
while($retry_count < 3 && $response === false)
{
$response = curl_exec($curl);
if($response === false)
{
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $vendor, $project, curl_error($curl), $retry_count + 1));
$retry_count++;
}
}
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $vendor, $project, curl_error($curl)));
}
switch(curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -472,11 +472,23 @@
*/
private static function processHttpResponse(CurlHandle $curl, string $group, string $project): array
{
$response = curl_exec($curl);
$retry_count = 0;
$response = false;
while($retry_count < 3 && $response === false)
{
$response = curl_exec($curl);
if($response === false)
{
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $vendor, $project, curl_error($curl), $retry_count + 1));
$retry_count++;
}
}
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $vendor, $project, curl_error($curl)));
}
switch (curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -495,11 +495,23 @@
*/
private static function processHttpResponse(CurlHandle $curl, string $group, string $project): array
{
$response = curl_exec($curl);
$retry_count = 0;
$response = false;
while($retry_count < 3 && $response === false)
{
$response = curl_exec($curl);
if($response === false)
{
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $vendor, $project, curl_error($curl), $retry_count + 1));
$retry_count++;
}
}
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $vendor, $project, curl_error($curl)));
}
switch (curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -231,7 +231,19 @@
*/
private static function processHttpResponse(CurlHandle $curl, string $vendor, string $project): array
{
$response = curl_exec($curl);
$retry_count = 0;
$response = false;
while($retry_count < 3 && $response === false)
{
$response = curl_exec($curl);
if($response === false)
{
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $vendor, $project, curl_error($curl), $retry_count + 1));
$retry_count++;
}
}
if($response === false)
{