From 1cc6e351f1aa5384e2eeb94a64ae60a0d9984201 Mon Sep 17 00:00:00 2001 From: Philipp Herzog Date: Mon, 10 Jun 2024 19:09:14 +0200 Subject: [PATCH] group remote builds by host --- src/cli.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 8642c39..1ace92e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -11,6 +11,7 @@ use futures_util::future::{join_all, try_join_all}; use tokio::try_join; use crate as deploy; +use crate::push::{PushProfileData, PushProfileError}; use self::deploy::{DeployFlake, ParseFlakeError}; use futures_util::stream::{StreamExt, TryStreamExt}; @@ -591,17 +592,21 @@ async fn run_deploy( data.deploy_data.merged_settings.remote_build.unwrap_or_default() }); - // await both the remote builds and the local builds to speed up deployment times + // the grouping by host will retain each hosts ordering by profiles_order since the fold is synchronous + let remote_build_map: HashMap<_, Vec<_>> = remote_builds.iter().fold(HashMap::new(), |mut accum, elem| { + match accum.get_mut(elem.deploy_data.node_name) { + Some(v) => { v.push(elem); accum }, + None => { accum.insert(elem.deploy_data.node_name, vec![elem]); accum } + } + }); + try_join!( - // remote builds can be run asynchronously since they do not affect the local machine - try_join_all(remote_builds.into_iter().map(|data| async { - let data = data; - deploy::push::build_profile(&data).await - })), + // remote builds can be run asynchronously (per host) + try_join_all(remote_build_map.into_iter().map(deploy_profiles_to_host)), async { // run local builds synchronously to prevent hardware deadlocks for data in &local_builds { - deploy::push::build_profile(data).await?; + deploy::push::build_profile(data).await.unwrap(); } // push all profiles asynchronously @@ -744,3 +749,10 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> { Ok(()) } + +async fn deploy_profiles_to_host<'a>((_host, profiles): (&str, Vec<&'a PushProfileData<'a>>)) -> Result<(), PushProfileError> { + for profile in &profiles { + deploy::push::build_profile(profile).await?; + }; + Ok(()) +}