Skip to content

Commit

Permalink
Remove config in favor of clap args
Browse files Browse the repository at this point in the history
  • Loading branch information
dynco-nym committed Oct 18, 2024
1 parent 00b737d commit 9be3902
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 94 deletions.
2 changes: 1 addition & 1 deletion nym-node-status-api/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn pretty_build_info_static() -> &'static str {
PRETTY_BUILD_INFORMATION.get_or_init(|| bin_info!().pretty_print())
}

#[derive(Parser, Debug)]
#[derive(Clone, Debug, Parser)]
#[clap(author = "Nymtech", version, long_version = pretty_build_info_static(), about)]
pub(crate) struct Cli {
/// Path pointing to an env file that configures the Nym API.
Expand Down
73 changes: 0 additions & 73 deletions nym-node-status-api/src/config.rs

This file was deleted.

18 changes: 6 additions & 12 deletions nym-node-status-api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use clap::Parser;
use nym_network_defaults::setup_env;
use nym_task::signal::wait_for_signal;

mod cli;
mod config;
mod db;
mod http;
mod logging;
Expand All @@ -14,31 +12,27 @@ async fn main() -> anyhow::Result<()> {
logging::setup_tracing_logger();

let args = cli::Cli::parse();
// if dotenv file is present, load its values
// otherwise, default to mainnet
setup_env(args.config_env_file.as_ref());

let connection_url = args.connection_url.clone();
let conf = config::Config::from_args(args);
tracing::debug!("Using config:\n{:#?}", conf);
tracing::debug!("Using config:\n{:#?}", args);

let storage = db::Storage::init(connection_url).await?;
let db_pool = storage.pool_owned().await;
let conf_clone = conf.clone();
let args_clone = args.clone();
tokio::spawn(async move {
monitor::spawn_in_background(db_pool, conf_clone).await;
monitor::spawn_in_background(db_pool, args_clone).await;
});
tracing::info!("Started monitor task");

let shutdown_handles = http::server::start_http_api(
storage.pool_owned().await,
conf.http_port(),
conf.nym_http_cache_ttl(),
args.http_port,
args.nym_http_cache_ttl,
)
.await
.expect("Failed to start server");

tracing::info!("Started HTTP server on port {}", conf.http_port());
tracing::info!("Started HTTP server on port {}", args.http_port);

wait_for_signal().await;

Expand Down
14 changes: 6 additions & 8 deletions nym-node-status-api/src/monitor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config::Config;
use crate::cli::Cli;
use crate::db::models::{
gateway, mixnode, GatewayRecord, MixnodeRecord, NetworkSummary, GATEWAYS_BLACKLISTED_COUNT,
GATEWAYS_BONDED_COUNT, GATEWAYS_EXPLORER_COUNT, GATEWAYS_HISTORICAL_COUNT,
Expand Down Expand Up @@ -29,7 +29,7 @@ static DELEGATION_PROGRAM_WALLET: &str = "n1rnxpdpx3kldygsklfft0gech7fhfcux4zst5

// TODO dz: query many NYM APIs:
// multiple instances running directory cache, ask sachin
pub(crate) async fn spawn_in_background(db_pool: DbPool, config: Config) -> JoinHandle<()> {
pub(crate) async fn spawn_in_background(db_pool: DbPool, config: Cli) -> JoinHandle<()> {
let network_defaults = nym_network_defaults::NymNetworkDetails::new_from_env();

loop {
Expand All @@ -54,7 +54,7 @@ pub(crate) async fn spawn_in_background(db_pool: DbPool, config: Config) -> Join
async fn run(
pool: &DbPool,
network_details: &NymNetworkDetails,
config: &Config,
config: &Cli,
) -> anyhow::Result<()> {
let default_api_url = network_details
.endpoints
Expand All @@ -70,10 +70,8 @@ async fn run(

let default_explorer_url =
default_explorer_url.expect("explorer url missing in network config");
let explorer_client = ExplorerClient::new_with_timeout(
default_explorer_url,
config.nym_explorer_client_timeout(),
)?;
let explorer_client =
ExplorerClient::new_with_timeout(default_explorer_url, config.explorer_client_timeout)?;
let explorer_gateways = explorer_client
.get_gateways()
.await
Expand Down Expand Up @@ -126,7 +124,7 @@ async fn run(
.await
.log_error("get_active_mixnodes")?;
let delegation_program_members =
get_delegation_program_details(network_details, config.nyxd_addr()).await?;
get_delegation_program_details(network_details, &config.nyxd_addr).await?;

// keep stats for later
let count_bonded_mixnodes = mixnodes.len();
Expand Down

0 comments on commit 9be3902

Please sign in to comment.