feat: add slot for upload strategy
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-25 21:34:09 +02:00
parent b980ac949e
commit cdae730c6b
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
2 changed files with 30 additions and 2 deletions

View File

@ -13,7 +13,25 @@ use tokio_stream::{wrappers::ReadDirStream, StreamExt};
use crate::components::{ConcreteComponent, IntoComponent};
pub async fn process() -> anyhow::Result<()> {
process_opts(Vec::<ConcreteComponent>::new(), ProcessOpts::default()).await
process_opts(
Vec::<ConcreteComponent>::new(),
ProcessOpts::default(),
None::<NoUploadStrategy>,
)
.await
}
pub trait UploadStrategy {
fn upload(&self, input_path: &Path) -> BoxFuture<'_, anyhow::Result<()>>;
}
#[derive(Default)]
pub struct NoUploadStrategy {}
impl UploadStrategy for NoUploadStrategy {
fn upload(&self, input_path: &Path) -> BoxFuture<'_, anyhow::Result<()>> {
async move { Ok(()) }.boxed()
}
}
pub struct ProcessOpts {
@ -42,6 +60,7 @@ const CUDDLE_PLAN_PATH_PREFIX: &str = ".cuddle/base";
pub async fn process_opts(
components: impl IntoIterator<Item = impl IntoComponent>,
opts: ProcessOpts,
upload_strategy: Option<impl UploadStrategy>,
) -> anyhow::Result<()> {
let components = components
.into_iter()
@ -76,6 +95,10 @@ pub async fn process_opts(
)
.await?;
if let Some(upload_strategy) = upload_strategy {
upload_strategy.upload(&opts.output).await?;
}
Ok(())
}

View File

@ -1,6 +1,9 @@
use std::{cmp::Ordering, collections::HashMap, path::Path};
use cuddle_clusters::{process::ProcessOpts, ConcreteComponent, IntoComponent};
use cuddle_clusters::{
process::{NoUploadStrategy, ProcessOpts},
ConcreteComponent, IntoComponent,
};
use walkdir::DirEntry;
pub(crate) async fn run_test_with_components(
@ -29,6 +32,7 @@ pub(crate) async fn run_test_with_components(
output: actual.clone(),
variables: HashMap::default(),
},
None::<NoUploadStrategy>,
)
.await?;
@ -40,6 +44,7 @@ pub(crate) async fn run_test_with_components(
output: expected.clone(),
variables: HashMap::default(),
},
None::<NoUploadStrategy>,
)
.await?;
}