Skip to content

Commit

Permalink
feat(rust): wait until the default node is up when initializing it
Browse files Browse the repository at this point in the history
  • Loading branch information
etorreborre committed May 27, 2024
1 parent c476abf commit a98f025
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions implementations/rust/ockam/ockam_command/src/node/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ pub async fn get_node_resources(
}
}

// Wait for a node to be up. We wait until the IS_NODE_ACCESSIBLE_TIMEOUT is passed and return `false`
// if the node is not up after that time.
pub async fn wait_until_node_is_up(
ctx: &Context,
cli_state: &CliState,
node_name: String,
) -> Result<bool> {
let mut node = BackgroundNodeClient::create(ctx, cli_state, &Some(node_name)).await?;
is_node_up(ctx, &mut node, true).await
}

/// Send message(s) to a node to determine if it is 'up' and
/// responding to requests.
///
Expand Down
3 changes: 3 additions & 0 deletions implementations/rust/ockam/ockam_command/src/node/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tracing::info;
use ockam_core::env::get_env_with_default;
use ockam_node::Context;

use crate::node::show::wait_until_node_is_up;
use crate::node::CreateCommand;
use crate::run::parser::resource::utils::subprocess_stdio;
use crate::shared_args::TrustOpts;
Expand Down Expand Up @@ -56,6 +57,8 @@ pub async fn initialize_default_node(
cmd.async_run(ctx, opts.clone()).await?;
opts.terminal.write_line("")?;
}
let node_name = opts.state.get_default_node().await?;
wait_until_node_is_up(ctx, &opts.state, node_name.name()).await?;
Ok(())
}

Expand Down

0 comments on commit a98f025

Please sign in to comment.