Skip to content

Commit

Permalink
feat: add interval arg to the start command
Browse files Browse the repository at this point in the history
This will be for starting nodes in a more controlled fashion, if an upgrade fails.
  • Loading branch information
jacderida committed Nov 3, 2024
1 parent 9519990 commit b677fdb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion resources/ansible/start_nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- name: ensure all nodes are started using the node manager
hosts: all
become: True
vars:
interval: "{{ interval }}"
tasks:
- name: start
ansible.builtin.command: safenode-manager start --interval 2000
ansible.builtin.command: "safenode-manager start --interval {{ interval }}"
14 changes: 9 additions & 5 deletions src/ansible/provisioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use evmlib::common::U256;
use log::{debug, error, trace};
use semver::Version;
use sn_service_management::NodeRegistry;
use std::{net::SocketAddr, path::PathBuf, time::Instant};
use std::{net::SocketAddr, path::PathBuf, time::{Instant, Duration}};
use walkdir::WalkDir;

use crate::ansible::extra_vars;
Expand Down Expand Up @@ -490,12 +490,16 @@ impl AnsibleProvisioner {
Ok(())
}

pub fn start_nodes(&self) -> Result<()> {
pub fn start_nodes(&self, interval: Duration) -> Result<()> {
let mut extra_vars = ExtraVarsDocBuilder::default();
extra_vars.add_variable("interval", &interval.as_millis().to_string());
for node_inv_type in AnsibleInventoryType::iter_node_type() {
self.ansible_runner
.run_playbook(AnsiblePlaybook::StartNodes, node_inv_type, None)?;
self.ansible_runner.run_playbook(
AnsiblePlaybook::StartNodes,
node_inv_type,
Some(extra_vars.build()),
)?;
}

Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ impl TestnetDeployer {
Ok(())
}

pub fn start(&self) -> Result<()> {
self.ansible_provisioner.start_nodes()?;
pub fn start(&self, interval: Duration) -> Result<()> {
self.ansible_provisioner.start_nodes(interval)?;
Ok(())
}

Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ enum Commands {
/// Maximum number of forks Ansible will use to execute tasks on target hosts.
#[clap(long, default_value_t = 50)]
forks: usize,
/// The interval between each node start in milliseconds.
#[clap(long, value_parser = |t: &str| -> Result<Duration> { Ok(t.parse().map(Duration::from_millis)?)}, default_value = "2000")]
interval: Duration,
/// The name of the environment.
#[arg(short = 'n', long)]
name: String,
Expand Down Expand Up @@ -1976,6 +1979,7 @@ async fn main() -> Result<()> {
}
Commands::Start {
forks,
interval,
name,
provider,
} => {
Expand All @@ -1996,7 +2000,7 @@ async fn main() -> Result<()> {
return Err(eyre!("The {name} environment does not exist"));
}

testnet_deployer.start()?;
testnet_deployer.start(interval)?;

Ok(())
}
Expand Down

0 comments on commit b677fdb

Please sign in to comment.