This commit is contained in:
		
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@ -2200,7 +2200,7 @@ dependencies = [
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "peach-config"
 | 
			
		||||
version = "0.1.26"
 | 
			
		||||
version = "0.1.27"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "async-std",
 | 
			
		||||
 "clap",
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "peach-config"
 | 
			
		||||
version = "0.1.26"
 | 
			
		||||
version = "0.1.27"
 | 
			
		||||
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
 | 
			
		||||
edition = "2018"
 | 
			
		||||
description = "Command line tool for installing, updating and configuring PeachCloud"
 | 
			
		||||
 | 
			
		||||
@ -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: {}",
 | 
			
		||||
 | 
			
		||||
@ -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<String, PeachConfigError> {
 | 
			
		||||
    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<String, PeachConfigError> {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        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()})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user