Skip to content

Commit

Permalink
Make refresh delay configurable in server & agent
Browse files Browse the repository at this point in the history
  • Loading branch information
dynco-nym committed Oct 28, 2024
1 parent d8a9864 commit 1be2a56
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nym-node-status-agent/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function copy_gw_probe() {
pushd $gateway_probe_src
cargo build --release --package nym-gateway-probe
cp target/release/nym-gateway-probe "$crate_root"
$NYM_GATEWAY_PROBE --version
$crate_root/nym-gateway-probe --version
popd
}

Expand Down
16 changes: 16 additions & 0 deletions nym-node-status-api/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ pub(crate) struct Cli {
/// Connection url for the database.
#[clap(long, env = "DATABASE_URL")]
pub(crate) database_url: String,

#[clap(
long,
default_value = "600",
env = "NODE_STATUS_API_MONITOR_REFRESH_INTERVAL"
)]
#[arg(value_parser = parse_duration)]
pub(crate) monitor_refresh_interval: Duration,

#[clap(
long,
default_value = "600",
env = "NODE_STATUS_API_TESTRUN_REFRESH_INTERVAL"
)]
#[arg(value_parser = parse_duration)]
pub(crate) testruns_refresh_interval: Duration,
}

fn parse_duration(arg: &str) -> Result<std::time::Duration, std::num::ParseIntError> {
Expand Down
3 changes: 2 additions & 1 deletion nym-node-status-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ async fn main() -> anyhow::Result<()> {
args_clone.explorer_client_timeout,
args_clone.nym_api_client_timeout,
&args_clone.nyxd_addr,
args_clone.monitor_refresh_interval,
)
.await;
tracing::info!("Started monitor task");
});
testruns::spawn(storage.pool_owned()).await;
testruns::spawn(storage.pool_owned(), args.testruns_refresh_interval).await;

let shutdown_handles = http::server::start_http_api(
storage.pool_owned(),
Expand Down
6 changes: 3 additions & 3 deletions nym-node-status-api/src/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use tokio::time::Duration;
use tracing::instrument;

// TODO dz should be configurable
const REFRESH_DELAY: Duration = Duration::from_secs(60 * 5);
const FAILURE_RETRY_DELAY: Duration = Duration::from_secs(60);

static DELEGATION_PROGRAM_WALLET: &str = "n1rnxpdpx3kldygsklfft0gech7fhfcux4zst5lw";
Expand All @@ -35,6 +34,7 @@ pub(crate) async fn spawn_in_background(
explorer_client_timeout: Duration,
nym_api_client_timeout: Duration,
nyxd_addr: &Url,
refresh_interval: Duration,
) {
let network_defaults = nym_network_defaults::NymNetworkDetails::new_from_env();

Expand All @@ -59,9 +59,9 @@ pub(crate) async fn spawn_in_background(
} else {
tracing::info!(
"Info successfully collected, sleeping for {}s...",
REFRESH_DELAY.as_secs()
refresh_interval.as_secs()
);
tokio::time::sleep(REFRESH_DELAY).await;
tokio::time::sleep(refresh_interval).await;
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions nym-node-status-api/src/testruns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ pub(crate) mod models;
mod queue;
pub(crate) use queue::now_utc;

// TODO dz should be configurable
const REFRESH_DELAY: Duration = Duration::from_secs(60 * 5);

pub(crate) async fn spawn(pool: DbPool) {
pub(crate) async fn spawn(pool: DbPool, refresh_interval: Duration) {
tokio::spawn(async move {
loop {
tracing::info!("Spawning testruns...");

if let Err(e) = run(&pool).await {
tracing::error!("Cron job failed: {}", e);
}
tracing::debug!("Sleeping for {}s...", REFRESH_DELAY.as_secs());
tokio::time::sleep(REFRESH_DELAY).await;
tracing::debug!("Sleeping for {}s...", refresh_interval.as_secs());
tokio::time::sleep(refresh_interval).await;
}
});
}
Expand Down Expand Up @@ -73,7 +70,7 @@ async fn run(pool: &DbPool) -> anyhow::Result<()> {
testruns_created += 1;
}
}
tracing::debug!("Queued {} testruns", testruns_created);
tracing::debug!("{} testruns queued in total", testruns_created);

Ok(())
}

0 comments on commit 1be2a56

Please sign in to comment.