diff options
author | rtkay123 <dev@kanjala.com> | 2025-08-17 20:02:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-17 20:02:49 +0200 |
commit | 73d7bab8844bb21c7a9143c30800c2d11d411e42 (patch) | |
tree | 955290bd2bded56b534738d6320216fbeeb708cb /crates/typologies/src/processor/driver.rs | |
parent | 725739985d853b07d73fa7fcd6db1f2f1b0000b6 (diff) | |
download | warden-73d7bab8844bb21c7a9143c30800c2d11d411e42.tar.bz2 warden-73d7bab8844bb21c7a9143c30800c2d11d411e42.zip |
feat: typology processor (#8)
Diffstat (limited to 'crates/typologies/src/processor/driver.rs')
-rw-r--r-- | crates/typologies/src/processor/driver.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/crates/typologies/src/processor/driver.rs b/crates/typologies/src/processor/driver.rs new file mode 100644 index 0000000..d150620 --- /dev/null +++ b/crates/typologies/src/processor/driver.rs @@ -0,0 +1,40 @@ +use tonic::IntoRequest; +use warden_core::configuration::typology::{TypologyConfiguration, TypologyConfigurationRequest}; + +use crate::state::AppHandle; + +pub trait GetTypologyConfiguration { + fn get_typology_config( + &self, + typology_key: TypologyConfigurationRequest, + ) -> impl std::future::Future<Output = anyhow::Result<TypologyConfiguration>> + Send; +} + +impl GetTypologyConfiguration for AppHandle { + async fn get_typology_config( + &self, + typology_key: TypologyConfigurationRequest, + ) -> anyhow::Result<TypologyConfiguration> { + { + let local_cache = self.local_cache.read().await; + if let Some(result) = local_cache.get(&typology_key).await.map(Ok) { + return result; + } + } + + let local_cache = self.local_cache.write().await; + let mut client = self.query_typology_client.clone(); + + let value = client + .get_typology_configuration(typology_key.clone().into_request()) + .await? + .into_inner() + .configuration + .ok_or_else(|| anyhow::anyhow!("configuration unavailable"))?; + local_cache + .insert(typology_key.clone(), value.clone()) + .await; + + Ok(value) + } +} |