Skip to content

Commit

Permalink
Merge pull request #2385 from RolandSherwin/stop_interval
Browse files Browse the repository at this point in the history
feat(manager): introduce sleep interval when stopping node services
  • Loading branch information
jacderida authored Nov 5, 2024
2 parents 529369d + e7f7e03 commit 05bfe18
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion node-launchpad/src/node_mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const NODE_ADD_MAX_RETRIES: u32 = 5;
pub fn stop_nodes(services: Vec<String>, action_sender: UnboundedSender<Action>) {
tokio::task::spawn_local(async move {
if let Err(err) =
sn_node_manager::cmd::node::stop(vec![], services, VerbosityLevel::Minimal).await
sn_node_manager::cmd::node::stop(None, vec![], services, VerbosityLevel::Minimal).await
{
error!("Error while stopping services {err:?}");
if let Err(err) =
Expand Down
8 changes: 7 additions & 1 deletion sn_node_manager/src/bin/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ pub enum SubCmd {
/// sudo if you defined system-wide services; otherwise, do not run the command elevated.
#[clap(name = "stop")]
Stop {
/// An interval applied between stopping each service.
///
/// Units are milliseconds.
#[clap(long, conflicts_with = "connection-timeout")]
interval: Option<u64>,
/// The peer ID of the service to stop.
///
/// The argument can be used multiple times to stop many services.
Expand Down Expand Up @@ -1367,9 +1372,10 @@ async fn main() -> Result<()> {
json,
}) => cmd::node::status(details, fail, json).await,
Some(SubCmd::Stop {
interval,
peer_id: peer_ids,
service_name: service_names,
}) => cmd::node::stop(peer_ids, service_names, verbosity).await,
}) => cmd::node::stop(interval, peer_ids, service_names, verbosity).await,
Some(SubCmd::Upgrade {
connection_timeout,
do_not_start,
Expand Down
12 changes: 10 additions & 2 deletions sn_node_manager/src/cmd/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pub async fn reset(force: bool, verbosity: VerbosityLevel) -> Result<()> {
}
}

stop(vec![], vec![], verbosity).await?;
stop(None, vec![], vec![], verbosity).await?;
remove(false, vec![], vec![], verbosity).await?;

// Due the possibility of repeated runs of the `reset` command, we need to check for the
Expand Down Expand Up @@ -406,6 +406,7 @@ pub async fn status(details: bool, fail: bool, json: bool) -> Result<()> {
}

pub async fn stop(
interval: Option<u64>,
peer_ids: Vec<String>,
service_names: Vec<String>,
verbosity: VerbosityLevel,
Expand Down Expand Up @@ -442,6 +443,13 @@ pub async fn stop(
let service = NodeService::new(node, Box::new(rpc_client));
let mut service_manager =
ServiceManager::new(service, Box::new(ServiceController {}), verbosity);

if service_manager.service.status() == ServiceStatus::Running {
if let Some(interval) = interval {
debug!("Sleeping for {} milliseconds", interval);
std::thread::sleep(std::time::Duration::from_millis(interval));
}
}
match service_manager.stop().await {
Ok(()) => {
debug!("Stopped service {}", node.service_name);
Expand Down Expand Up @@ -662,7 +670,7 @@ pub async fn maintain_n_running_nodes(
"Stopping {} excess nodes: {:?}",
to_stop_count, services_to_stop
);
stop(vec![], services_to_stop, verbosity).await?;
stop(None, vec![], services_to_stop, verbosity).await?;
}
Ordering::Less => {
let to_start_count = target_count - running_count;
Expand Down

0 comments on commit 05bfe18

Please sign in to comment.