diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2024-02-06 14:47:18 +0100 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2024-02-06 14:47:18 +0100 |
commit | 5bd099131800e4ac420ac75ed6c312f6304f1aed (patch) | |
tree | ea7ab813842edae22acce56d58a51aded51755ec | |
parent | a074ecb2513803fa4fa91199d1f4ec2101bb34b2 (diff) | |
download | FlightCore-5bd099131800e4ac420ac75ed6c312f6304f1aed.tar.gz FlightCore-5bd099131800e4ac420ac75ed6c312f6304f1aed.zip |
feat: Retry package index fetch on failure
with wait time in-between and max number of retries.
-rw-r--r-- | src-tauri/src/northstar/install.rs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index e0653ddb..9d9b43d1 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -243,18 +243,31 @@ async fn do_install( Ok(()) } +/// Attempt to get Thunderstore index with wait and retry on failure +fn get_package_index_with_retry() -> Result<Vec<thermite::model::Mod>, String> { + let retry_times = 3; // Number of retry attempts + let wait_time = 1; // Number of seconds to wait before retrying + for _ in 0..retry_times { + match thermite::api::get_package_index() { + Ok(res) => return Ok(res.to_vec()), + Err(err) => { + log::warn!("Failed fetching package index due to: {}", err); + std::thread::sleep(std::time::Duration::from_secs(wait_time)); + } + } + } + Err("Failed to connect to Thunderstore.".to_string()) +} + pub async fn install_northstar( window: tauri::Window, game_install: GameInstall, northstar_package_name: String, version_number: Option<String>, ) -> Result<String, String> { - let index = match thermite::api::get_package_index() { - Ok(res) => res.to_vec(), - Err(err) => { - log::warn!("Failed fetching package index due to: {err}"); - return Err("Failed to connect to Thunderstore.".to_string()); - } + let index = match get_package_index_with_retry() { + Ok(res) => res, + Err(err) => return Err(err), }; let nmod = index .iter() |