diff --git a/src/config.rs b/src/config.rs index 8c21597..ea52dd2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,29 @@ use std::str::FromStr; use std::time::Duration; use url::Url; +/// this is for internal use only, please don't use this macro. +#[doc(hidden)] +#[macro_export] +macro_rules! __cfg { + (@val $key:expr) => { + std::env::var(concat!("HYDRANT_", $key)) + }; + ($key:expr, $default:expr, sec) => { + cfg!(@val $key) + .ok() + .and_then(|s| humantime::parse_duration(&s).ok()) + .unwrap_or($default) + }; + ($key:expr, $default:expr) => { + cfg!(@val $key) + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or($default.to_owned()) + .into() + }; +} +use crate::__cfg as cfg; + /// loads `.env` from the current directory, setting any variables not already in the environment. fn load_dotenv() { let Ok(contents) = std::fs::read_to_string(".env") else { @@ -367,25 +390,6 @@ impl Config { pub fn from_env() -> Result { load_dotenv(); - macro_rules! cfg { - (@val $key:expr) => { - std::env::var(concat!("HYDRANT_", $key)) - }; - ($key:expr, $default:expr, sec) => { - cfg!(@val $key) - .ok() - .and_then(|s| humantime::parse_duration(&s).ok()) - .unwrap_or($default) - }; - ($key:expr, $default:expr) => { - cfg!(@val $key) - .ok() - .and_then(|s| s.parse().ok()) - .unwrap_or($default.to_owned()) - .into() - }; - } - // full_network is read first since it determines which defaults to use. let full_network: bool = cfg!("FULL_NETWORK", false); let defaults = full_network diff --git a/src/control/repos.rs b/src/control/repos.rs index 3e1fd81..7cb71e3 100644 --- a/src/control/repos.rs +++ b/src/control/repos.rs @@ -57,8 +57,8 @@ pub struct RepoInfo { /// control over which repositories are tracked and access to their state. /// /// in `filter` mode, a repo is only indexed if it either matches a signal or is -/// explicitly tracked via [`ReposControl::track`]. in `full` mode all repos are indexed -/// and tracking is implicit. +/// explicitly tracked via [`ReposControl::track`]. in `full` mode all repos are +/// indexed and tracking is implicit. /// /// tracking a DID that hydrant has never seen enqueues an immediate backfill. /// tracking a DID that hydrant already knows about (but has marked untracked) diff --git a/src/crawler/list_repos.rs b/src/crawler/list_repos.rs index b0f7b7c..ee23f50 100644 --- a/src/crawler/list_repos.rs +++ b/src/crawler/list_repos.rs @@ -381,7 +381,7 @@ impl SignalChecker { let valid_set: std::collections::HashSet<&Did<'static>> = valid.iter().collect(); Ok(in_flight .into_iter() - .filter(|g| valid_set.contains(&**g)) + .filter(|g| valid_set.contains(g.as_did())) .collect()) } } diff --git a/src/crawler/mod.rs b/src/crawler/mod.rs index 8b02467..5852b48 100644 --- a/src/crawler/mod.rs +++ b/src/crawler/mod.rs @@ -49,6 +49,12 @@ pub(super) struct InFlightGuard { pub(super) did: Did<'static>, } +impl InFlightGuard { + fn as_did(&self) -> &Did<'static> { + &self.did + } +} + impl std::ops::Deref for InFlightGuard { type Target = Did<'static>; fn deref(&self) -> &Did<'static> { diff --git a/src/db/ephemeral.rs b/src/db/ephemeral.rs index 6adca11..b3c044c 100644 --- a/src/db/ephemeral.rs +++ b/src/db/ephemeral.rs @@ -32,7 +32,7 @@ pub fn ephemeral_ttl_tick(db: &Db, ttl: &Duration) -> miette::Result<()> { let cutoff_key = keys::event_watermark_key(cutoff_ts); let cutoff_event_id = db .cursors - .range(..=cutoff_key.clone()) + .range(..=cutoff_key.as_slice()) .next_back() .map(|g| g.into_inner().into_diagnostic()) .transpose()? diff --git a/src/main.rs b/src/main.rs index 9935156..5ba7311 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use futures::FutureExt; use hydrant::config::Config; use hydrant::control::Hydrant; use mimalloc::MiMalloc; @@ -10,17 +11,11 @@ struct AppConfig { impl AppConfig { fn from_env() -> Self { - macro_rules! cfg { - ($key:expr, $default:expr) => { - std::env::var(concat!("HYDRANT_", $key)) - .ok() - .and_then(|s| s.parse().ok()) - .unwrap_or($default) - }; - } + use hydrant::__cfg as cfg; let api_port = cfg!("API_PORT", 3000u16); let enable_debug = cfg!("ENABLE_DEBUG", false); - let debug_port = cfg!("DEBUG_PORT", api_port + 1); + let debug_port: u16 = api_port + 1; + let debug_port = cfg!("DEBUG_PORT", debug_port); Self { api_port, enable_debug, @@ -48,16 +43,14 @@ async fn main() -> miette::Result<()> { let hydrant = Hydrant::new(cfg).await?; - if app.enable_debug { - tokio::select! { - r = hydrant.run()? => r, - r = hydrant.serve(app.api_port) => r, - r = hydrant.serve_debug(app.debug_port) => r, - } - } else { - tokio::select! { - r = hydrant.run()? => r, - r = hydrant.serve(app.api_port) => r, - } + let debug_fut = app + .enable_debug + .then(|| hydrant.serve_debug(app.debug_port).boxed()) + .unwrap_or_else(|| std::future::pending().boxed()); + + tokio::select! { + r = hydrant.run()? => r, + r = hydrant.serve(app.api_port) => r, + r = debug_fut => r, } }