From b2e3d5f3a35e557a3f158f9efbe3f3b587f7392d Mon Sep 17 00:00:00 2001 From: Mark Sinclair Date: Wed, 15 Sep 2021 14:12:29 +0100 Subject: [PATCH] explorer-api: add `DEV_MDOE` env var that doesn't run the task to resolve geo locations of mix nodes when in dev mode --- explorer-api/src/country_statistics/mod.rs | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/explorer-api/src/country_statistics/mod.rs b/explorer-api/src/country_statistics/mod.rs index 6f588e4eef..d0b3739c6a 100644 --- a/explorer-api/src/country_statistics/mod.rs +++ b/explorer-api/src/country_statistics/mod.rs @@ -4,6 +4,7 @@ use reqwest::Error as ReqwestError; use crate::country_statistics::country_nodes_distribution::CountryNodesDistribution; use crate::mix_nodes::{GeoLocation, Location}; use crate::state::ExplorerApiStateContext; +use std::env; pub mod country_nodes_distribution; pub mod http; @@ -18,18 +19,21 @@ impl CountryStatistics { } pub(crate) fn start(mut self) { - info!("Spawning task runner..."); - tokio::spawn(async move { - let mut interval_timer = tokio::time::interval(std::time::Duration::from_secs(60 * 60)); - loop { - // wait for the next interval tick - interval_timer.tick().await; + if env::var("DEV_MODE").is_err() { + info!("Spawning task runner..."); + tokio::spawn(async move { + let mut interval_timer = + tokio::time::interval(std::time::Duration::from_secs(60 * 60)); + loop { + // wait for the next interval tick + interval_timer.tick().await; - info!("Running task..."); - self.calculate_nodes_per_country().await; - info!("Done"); - } - }); + info!("Running task..."); + self.calculate_nodes_per_country().await; + info!("Done"); + } + }); + } } /// Retrieves the current list of mixnodes from the validators and calculates how many nodes are in each country