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

@ -473,12 +473,24 @@
* @throws NetworkException
*/
private static function processHttpResponse(CurlHandle $curl, string $group, string $project): array
{
$retry_count = 0;
$response = false;
while($retry_count < 3 && $response === false)
{
$response = curl_exec($curl);
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
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', $vendor, $project, curl_error($curl)));
}
switch(curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -471,12 +471,24 @@
* @throws NetworkException
*/
private static function processHttpResponse(CurlHandle $curl, string $group, string $project): array
{
$retry_count = 0;
$response = false;
while($retry_count < 3 && $response === false)
{
$response = curl_exec($curl);
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
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', $vendor, $project, curl_error($curl)));
}
switch (curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -494,12 +494,24 @@
* @throws NetworkException
*/
private static function processHttpResponse(CurlHandle $curl, string $group, string $project): array
{
$retry_count = 0;
$response = false;
while($retry_count < 3 && $response === false)
{
$response = curl_exec($curl);
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
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', $vendor, $project, curl_error($curl)));
}
switch (curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -230,9 +230,21 @@
* @throws NetworkException
*/
private static function processHttpResponse(CurlHandle $curl, string $vendor, string $project): array
{
$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', $vendor, $project, curl_error($curl)));