From 93e73cc66e8828e08717143cc4cc39f5fea008be Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 27 Nov 2023 19:14:31 +0100 Subject: [PATCH] feat: with mutex Signed-off-by: kjuulh --- crates/cuddle-ci/Cargo.toml | 1 + crates/cuddle-ci/src/cli.rs | 37 ++++++++++++++--------- crates/cuddle-ci/src/dagger_middleware.rs | 1 + 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/crates/cuddle-ci/Cargo.toml b/crates/cuddle-ci/Cargo.toml index 077f069..cfcf24d 100644 --- a/crates/cuddle-ci/Cargo.toml +++ b/crates/cuddle-ci/Cargo.toml @@ -17,6 +17,7 @@ eyre.workspace = true clap.workspace = true async-trait.workspace = true futures.workspace = true +tokio.workspace = true [dev-dependencies] tokio.workspace = true diff --git a/crates/cuddle-ci/src/cli.rs b/crates/cuddle-ci/src/cli.rs index bccd6c9..8e86036 100644 --- a/crates/cuddle-ci/src/cli.rs +++ b/crates/cuddle-ci/src/cli.rs @@ -1,18 +1,19 @@ use std::sync::Arc; use async_trait::async_trait; +use tokio::sync::Mutex; pub struct CuddleCI { - pr_action: Arc, - main_action: Arc, - release_action: Arc, + pr_action: Arc>, + main_action: Arc>, + release_action: Arc>, } impl CuddleCI { pub fn new( - pr: Arc, - main: Arc, - release: Arc, + pr: Arc>, + main: Arc>, + release: Arc>, ) -> Self { Self { pr_action: pr, @@ -21,19 +22,25 @@ impl CuddleCI { } } - pub fn with_pull_request(&mut self, pr: Arc) -> &mut Self { + pub fn with_pull_request( + &mut self, + pr: Arc>, + ) -> &mut Self { self.pr_action = pr; self } - pub fn with_main(&mut self, main: Arc) -> &mut Self { + pub fn with_main(&mut self, main: Arc>) -> &mut Self { self.main_action = main; self } - pub fn with_release(&mut self, release: Arc) -> &mut Self { + pub fn with_release( + &mut self, + release: Arc>, + ) -> &mut Self { self.release_action = release; self @@ -52,17 +59,17 @@ impl CuddleCI { Some((name, args)) => match (name, args) { ("pr", _args) => { eprintln!("starting pr validate"); - self.pr_action.execute_pull_request().await?; + self.pr_action.lock().await.execute_pull_request().await?; eprintln!("finished pr validate"); } ("main", _args) => { eprintln!("starting main validate"); - self.main_action.execute_main().await?; + self.main_action.lock().await.execute_main().await?; eprintln!("finished main validate"); } ("release", _args) => { eprintln!("starting release validate"); - self.release_action.execute_release().await?; + self.release_action.lock().await.execute_release().await?; eprintln!("finished release validate"); } (command_name, _) => { @@ -79,9 +86,9 @@ impl CuddleCI { impl Default for CuddleCI { fn default() -> Self { Self::new( - Arc::new(DefaultPullRequestAction {}), - Arc::new(DefaultMainAction {}), - Arc::new(DefaultReleaseAction {}), + Arc::new(Mutex::new(DefaultPullRequestAction {})), + Arc::new(Mutex::new(DefaultMainAction {})), + Arc::new(Mutex::new(DefaultReleaseAction {})), ) } } diff --git a/crates/cuddle-ci/src/dagger_middleware.rs b/crates/cuddle-ci/src/dagger_middleware.rs index 1c6c2ab..826de75 100644 --- a/crates/cuddle-ci/src/dagger_middleware.rs +++ b/crates/cuddle-ci/src/dagger_middleware.rs @@ -1,6 +1,7 @@ use async_trait::async_trait; use dagger_sdk::Container; use std::{future::Future, pin::Pin}; + pub type DynMiddleware = Box; #[async_trait]