From 1a6b6e3ef310c8eea37b55f8007c85a8772ff8e9 Mon Sep 17 00:00:00 2001 From: Yureka Date: Mon, 17 Jun 2024 01:10:55 +0200 Subject: feat(tvix/castore): add composition module Change-Id: I0868f3278db85ae5fe030089ee9033837bc08748 Signed-off-by: Yureka Reviewed-on: https://cl.tvl.fyi/c/depot/+/11853 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/castore/src/directoryservice/combinators.rs | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tvix/castore/src/directoryservice/combinators.rs') diff --git a/tvix/castore/src/directoryservice/combinators.rs b/tvix/castore/src/directoryservice/combinators.rs index d3f351d6b689..2364a313d5f4 100644 --- a/tvix/castore/src/directoryservice/combinators.rs +++ b/tvix/castore/src/directoryservice/combinators.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use futures::stream::BoxStream; use futures::StreamExt; use futures::TryFutureExt; @@ -6,6 +8,7 @@ use tonic::async_trait; use tracing::{instrument, trace}; use super::{DirectoryGraph, DirectoryService, RootToLeavesValidator, SimplePutter}; +use crate::composition::{CompositionContext, ServiceBuilder}; use crate::directoryservice::DirectoryPutter; use crate::proto; use crate::B3Digest; @@ -140,3 +143,29 @@ where Box::new(SimplePutter::new((*self).clone())) } } + +#[derive(serde::Deserialize, Debug)] +#[serde(deny_unknown_fields)] +pub struct CacheConfig { + near: String, + far: String, +} + +#[async_trait] +impl ServiceBuilder for CacheConfig { + type Output = dyn DirectoryService; + async fn build<'a>( + &'a self, + _instance_name: &str, + context: &CompositionContext, + ) -> Result, Box> { + let (near, far) = futures::join!( + context.resolve(self.near.clone()), + context.resolve(self.far.clone()) + ); + Ok(Arc::new(Cache { + near: near?, + far: far?, + })) + } +} -- cgit 1.4.1