Skip to content

Commit

Permalink
group remote builds by host
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilTaken committed Jun 10, 2024
1 parent c6bbeec commit 1cc6e35
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(())
}

0 comments on commit 1cc6e35

Please sign in to comment.