diff --git a/src/cache.rs b/src/cache.rs index 70fc586..bee5da6 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -11,11 +11,11 @@ const MAX_CACHE_AGE : i64 = 86400; #[derive(Default)] pub struct InstanceCache { - store: RwLock>, + store: RwLock)>>, } impl InstanceCache { - pub async fn instance_metadata(&self, domain: &str) -> reqwest::Result { + pub async fn instance_metadata(&self, domain: &str) -> reqwest::Result> { let now = Utc::now().timestamp(); if let Some((age, value)) = self.store.read().await.get(domain) { @@ -24,15 +24,18 @@ impl InstanceCache { } } - let value = reqwest::Client::builder() + let response = reqwest::Client::builder() .timeout(Duration::from_secs(5)) .build()? .get(format!("https://{}/nodeinfo/2.0.json", domain)) .send() - .await? - .json::() .await?; + let value = response + .json::() + .await + .ok(); + self.store.write().await.insert(domain.to_string(), (now, value.clone())); Ok(value) diff --git a/src/main.rs b/src/main.rs index c65dd83..b573b43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,7 +68,11 @@ async fn scan_instance(domain: &str, map: Arc>) -> Option<()> { tracing::debug!("scanning instance {}", domain); let response = match CACHE.instance_metadata(domain).await { - Ok(r) => r, + Ok(Some(r)) => r, + Ok(None) => { + tracing::info!("instance {} doesn't provide metadata", domain); + return None + }, Err(e) => { tracing::warn!("could not fetch metadata for {}: {}", domain, e); return None