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:
parent
27d1609b23
commit
b2234d5040
2 changed files with 15 additions and 7 deletions
|
@ -13,6 +13,7 @@ This update introduces minor bug fixes.
|
||||||
### Changed
|
### Changed
|
||||||
- Update progress bar text to display basename only
|
- Update progress bar text to display basename only
|
||||||
- Updated exception handling in PackageReader
|
- Updated exception handling in PackageReader
|
||||||
|
- Updated the Download function to attempt to retry the download upon an error for at least 3 times.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Improve build efficiency by preventing duplicate merges
|
- Improve build efficiency by preventing duplicate merges
|
||||||
|
|
|
@ -861,7 +861,7 @@
|
||||||
* @throws NetworkException
|
* @throws NetworkException
|
||||||
* @noinspection UnusedFunctionResultInspection
|
* @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));
|
$file_path = basename(parse_url($url, PHP_URL_PATH));
|
||||||
$curl = curl_init($url);
|
$curl = curl_init($url);
|
||||||
|
@ -934,17 +934,24 @@
|
||||||
curl_exec($curl);
|
curl_exec($curl);
|
||||||
fclose($file_handle);
|
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->setMaxValue(100);
|
||||||
$progress_bar->setValue(100);
|
$progress_bar->setValue(100);
|
||||||
$progress_bar->setMiscText('done', true);
|
$progress_bar->setMiscText('done', true);
|
||||||
unset($progress_bar);
|
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);
|
curl_close($curl);
|
||||||
return $file_path;
|
return $file_path;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue