Skip to content

Commit a70a339

Browse files
committed
group remote builds by host
1 parent 91ce286 commit a70a339

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/cli.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use futures_util::future::{join_all, try_join_all};
1111
use tokio::try_join;
1212

1313
use crate as deploy;
14+
use crate::push::{PushProfileData, PushProfileError};
1415

1516
use self::deploy::{DeployFlake, ParseFlakeError};
1617
use futures_util::stream::{StreamExt, TryStreamExt};
@@ -593,17 +594,21 @@ async fn run_deploy(
593594
data.deploy_data.merged_settings.remote_build.unwrap_or_default()
594595
});
595596

596-
// await both the remote builds and the local builds to speed up deployment times
597+
// the grouping by host will retain each hosts ordering by profiles_order since the fold is synchronous
598+
let remote_build_map: HashMap<_, Vec<_>> = remote_builds.iter().fold(HashMap::new(), |mut accum, elem| {
599+
match accum.get_mut(elem.deploy_data.node_name) {
600+
Some(v) => { v.push(elem); accum },
601+
None => { accum.insert(elem.deploy_data.node_name, vec![elem]); accum }
602+
}
603+
});
604+
597605
try_join!(
598-
// remote builds can be run asynchronously since they do not affect the local machine
599-
try_join_all(remote_builds.into_iter().map(|data| async {
600-
let data = data;
601-
deploy::push::build_profile(&data).await
602-
})),
606+
// remote builds can be run asynchronously (per host)
607+
try_join_all(remote_build_map.into_iter().map(deploy_profiles_to_host)),
603608
async {
604609
// run local builds synchronously to prevent hardware deadlocks
605610
for data in &local_builds {
606-
deploy::push::build_profile(data).await?;
611+
deploy::push::build_profile(data).await.unwrap();
607612
}
608613

609614

@@ -750,3 +755,10 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
750755

751756
Ok(())
752757
}
758+
759+
async fn deploy_profiles_to_host<'a>((_host, profiles): (&str, Vec<&'a PushProfileData<'a>>)) -> Result<(), PushProfileError> {
760+
for profile in &profiles {
761+
deploy::push::build_profile(profile).await?;
762+
};
763+
Ok(())
764+
}

0 commit comments

Comments
 (0)