From 29f5ad0e8484b9f4c75fe0380f73b826b942a4f9 Mon Sep 17 00:00:00 2001 From: notplants Date: Tue, 12 Jul 2022 12:18:39 +0200 Subject: [PATCH] Wait for sbot is working --- Cargo.lock | 2 +- peach-config/Cargo.toml | 2 +- peach-config/src/main.rs | 4 +++- peach-config/src/wait_for_sbot.rs | 7 ++++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ffaa736..539ecef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2200,7 +2200,7 @@ dependencies = [ [[package]] name = "peach-config" -version = "0.1.26" +version = "0.1.27" dependencies = [ "async-std", "clap", diff --git a/peach-config/Cargo.toml b/peach-config/Cargo.toml index a81b605..f81ed62 100644 --- a/peach-config/Cargo.toml +++ b/peach-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peach-config" -version = "0.1.26" +version = "0.1.27" authors = ["Andrew Reid ", "Max Fowler "] edition = "2018" description = "Command line tool for installing, updating and configuring PeachCloud" diff --git a/peach-config/src/main.rs b/peach-config/src/main.rs index 96493a6..47e8b43 100644 --- a/peach-config/src/main.rs +++ b/peach-config/src/main.rs @@ -200,7 +200,9 @@ async fn run() { }, PeachConfig::WaitForSbot => { match wait_for_sbot::wait_for_sbot().await { - Ok(_) => {} + Ok(sbot_id) => { + println!("connected with sbot and found sbot_id: {:?}", sbot_id) + } Err(err) => { error!( "peach-config did not successfully connect to sbot: {}", diff --git a/peach-config/src/wait_for_sbot.rs b/peach-config/src/wait_for_sbot.rs index d291e95..239e81a 100644 --- a/peach-config/src/wait_for_sbot.rs +++ b/peach-config/src/wait_for_sbot.rs @@ -5,11 +5,11 @@ use peach_lib::sbot::init_sbot; /// Utility function to wait for a successful whoami call with sbot /// After each attempt to call whoami it waits 2 seconds, -/// and if after max_num_attempts (8) there is no successful whoami call +/// and if after max_num_attempts (10) there is no successful whoami call /// it returns an Error. Otherwise it returns Ok(sbot_id). pub async fn wait_for_sbot() -> Result { let mut num_attempts = 0; - let max_num_attempts = 8; + let max_num_attempts = 10; let mut sbot_is_running = 0; let mut whoami = None; while (sbot_is_running == 0) & (num_attempts < max_num_attempts) { @@ -32,10 +32,11 @@ pub async fn wait_for_sbot() -> Result { } }; if sbot_is_running == 0 { + println!("trying again {:?}", num_attempts); num_attempts += 1; let two_seconds = time::Duration::from_secs(2); thread::sleep(two_seconds); } }; - whoami.ok_or(PeachConfigError::WaitForSbotError{ message: "Failed to find sbot_id".to_string()}) + whoami.ok_or(PeachConfigError::WaitForSbotError{ message: "Failed to find sbot_id after 10 attempts".to_string()}) }