Skip to content

Commit

Permalink
feat: provide --interval arg for upgrade cmd
Browse files Browse the repository at this point in the history
This was another community feedback request.

As with the `start` command, a time-based interval is applied between each node being upgraded.

We will probably need something more sophisticated, but this simple mechanism should hopefully be
useful for now.
  • Loading branch information
jacderida committed Apr 17, 2024
1 parent e42cccd commit 9b15523
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sn_node_manager/src/bin/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ pub enum SubCmd {
/// Required if we want to downgrade, or for testing purposes.
#[clap(long)]
force: bool,
/// An interval applied between upgrading each service.
///
/// Units are milliseconds.
#[clap(long, default_value_t = 200)]
interval: u64,
/// Provide a path for the safenode binary to be used by the service.
///
/// Useful for upgrading the service using a custom built binary.
Expand Down Expand Up @@ -764,6 +769,7 @@ async fn main() -> Result<()> {
SubCmd::Upgrade {
do_not_start,
force,
interval,
path,
peer_id: peer_ids,
service_name: service_names,
Expand All @@ -775,6 +781,7 @@ async fn main() -> Result<()> {
do_not_start,
path,
force,
interval,
peer_ids,
provided_env_variable,
service_names,
Expand Down
6 changes: 6 additions & 0 deletions sn_node_manager/src/cmd/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use sn_service_management::{
};
use sn_transfers::HotWallet;
use std::{io::Write, net::Ipv4Addr, path::PathBuf, str::FromStr};
use tracing::debug;

pub async fn add(
count: Option<u16>,
Expand Down Expand Up @@ -264,6 +265,7 @@ pub async fn start(
let service = NodeService::new(node, Box::new(rpc_client));
let mut service_manager =
ServiceManager::new(service, Box::new(ServiceController {}), verbosity.clone());
debug!("Sleeping for {} milliseconds", interval);
std::thread::sleep(std::time::Duration::from_millis(interval));
match service_manager.start().await {
Ok(()) => {
Expand Down Expand Up @@ -363,6 +365,7 @@ pub async fn upgrade(
do_not_start: bool,
custom_bin_path: Option<PathBuf>,
force: bool,
interval: u64,
peer_ids: Vec<String>,
provided_env_variables: Option<Vec<(String, String)>>,
service_names: Vec<String>,
Expand Down Expand Up @@ -449,6 +452,9 @@ pub async fn upgrade(
));
}
}

debug!("Sleeping for {} milliseconds", interval);
std::thread::sleep(std::time::Duration::from_millis(interval));
}

node_registry.save()?;
Expand Down

0 comments on commit 9b15523

Please sign in to comment.