Updated the Download function to attempt to retry the download upon an error for at least 3 times.

Updated the downloadFile function in PackageManager.php to retry the download upon an error for at least 3 times. This improvement on error handling will enhance the resilience of the download process, reducing the likelihood of a single network hiccup resulting in a failed download. This change has also been reflected in the CHANGELOG.md file.
This commit is contained in:
Netkas 2023-10-25 14:33:42 -04:00
parent 27d1609b23
commit b2234d5040
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
2 changed files with 15 additions and 7 deletions

View file

@ -13,6 +13,7 @@ This update introduces minor bug fixes.
### Changed
- Update progress bar text to display basename only
- Updated exception handling in PackageReader
- Updated the Download function to attempt to retry the download upon an error for at least 3 times.
### Fixed
- Improve build efficiency by preventing duplicate merges

View file

@ -861,7 +861,7 @@
* @throws NetworkException
* @noinspection UnusedFunctionResultInspection
*/
private function downloadFile(string $url, string $path): string
private function downloadFile(string $url, string $path, int $retries=3): string
{
$file_path = basename(parse_url($url, PHP_URL_PATH));
$curl = curl_init($url);
@ -934,17 +934,24 @@
curl_exec($curl);
fclose($file_handle);
if(curl_errno($curl))
{
ShutdownHandler::declareTemporaryPath($file_path);
if($retries === 0)
{
throw new NetworkException(sprintf('Failed to download file from %s: %s', $url, curl_error($curl)));
}
Console::outWarning(sprintf('Failed to download file from %s: %s, retrying', $url, curl_error($curl)));
return $this->downloadFile($url, $path, ($retries - 1));
}
$progress_bar->setMaxValue(100);
$progress_bar->setValue(100);
$progress_bar->setMiscText('done', true);
unset($progress_bar);
if(curl_errno($curl))
{
ShutdownHandler::declareTemporaryPath($file_path);
throw new NetworkException(sprintf('Failed to download file from %s: %s', $url, curl_error($curl)));
}
curl_close($curl);
return $file_path;
}