Skip to content

Commit

Permalink
fix(#345): use cached links when req fails
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <[email protected]>
  • Loading branch information
brooksmtownsend committed Aug 5, 2024
1 parent 05cfd3e commit ce536fb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/wadm/src/storage/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::sync::Arc;

use tokio::sync::RwLock;
use tracing::debug;
use wasmcloud_control_interface::InterfaceLinkDefinition;
use wasmcloud_secrets_types::SecretConfig;

Expand Down Expand Up @@ -86,7 +87,14 @@ where
.into_iter()
.map(|(key, val)| (key, serde_json::to_value(val).unwrap()))
.collect::<HashMap<_, _>>();
let links = self.lattice_source.get_links().await?;

// If we fail to get the links, that likely just means the lattice source is down, so we
// just fall back on what we have cached
if let Ok(links) = self.lattice_source.get_links().await {
*self.links.write().await = links;
} else {
debug!("Failed to get links from lattice source, using cached links");
};

{
let mut stored_state = self.stored_state.write().await;
Expand All @@ -95,8 +103,6 @@ where
stored_state.insert(Host::KIND.to_owned(), hosts);
}

*self.links.write().await = links;

Ok(())
}
}
Expand Down

0 comments on commit ce536fb

Please sign in to comment.