Skip to content

Commit 91ce286

Browse files
committed
build and push profiles asynchronously
build remote builds (remote_build = true) asynchronously to speed up the deployment process. local builds should not be run asynchronously to prevent running into hardware deadlocks
1 parent 3867348 commit 91ce286

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/cli.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::collections::HashMap;
77
use std::io::{stdin, stdout, Write};
88

99
use clap::{ArgMatches, Clap, FromArgMatches};
10+
use futures_util::future::{join_all, try_join_all};
11+
use tokio::try_join;
1012

1113
use crate as deploy;
1214

@@ -587,19 +589,35 @@ async fn run_deploy(
587589
)
588590
};
589591

590-
for data in data_iter() {
591-
let node_name: String = data.deploy_data.node_name.to_string();
592-
deploy::push::build_profile(data).await.map_err(|e| {
593-
RunDeployError::BuildProfile(node_name, e)
594-
})?;
595-
}
592+
let (remote_builds, local_builds): (Vec<_>, Vec<_>) = data_iter().partition(|data| {
593+
data.deploy_data.merged_settings.remote_build.unwrap_or_default()
594+
});
595+
596+
// await both the remote builds and the local builds to speed up deployment times
597+
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+
})),
603+
async {
604+
// run local builds synchronously to prevent hardware deadlocks
605+
for data in &local_builds {
606+
deploy::push::build_profile(data).await?;
607+
}
608+
609+
610+
// push all profiles asynchronously
611+
join_all(local_builds.into_iter().map(|data| async {
612+
let data = data;
613+
deploy::push::push_profile(&data).await
614+
})).await;
615+
Ok(())
616+
}
617+
).map_err(|e| {
618+
RunDeployError::BuildProfile(node_name, e)
619+
})?;
596620

597-
for data in data_iter() {
598-
let node_name: String = data.deploy_data.node_name.to_string();
599-
deploy::push::push_profile(data).await.map_err(|e| {
600-
RunDeployError::PushProfile(node_name, e)
601-
})?;
602-
}
603621

604622
let mut succeeded: Vec<(&deploy::DeployData, &deploy::DeployDefs)> = vec![];
605623

src/push.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub async fn build_profile_remotely(data: &PushProfileData<'_>, derivation_name:
210210
Ok(())
211211
}
212212

213-
pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileError> {
213+
pub async fn build_profile(data: &PushProfileData<'_>) -> Result<(), PushProfileError> {
214214
debug!(
215215
"Finding the deriver of store path for {}",
216216
&data.deploy_data.profile.profile_settings.path
@@ -287,7 +287,7 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
287287
Ok(())
288288
}
289289

290-
pub async fn push_profile(data: PushProfileData<'_>) -> Result<(), PushProfileError> {
290+
pub async fn push_profile(data: &PushProfileData<'_>) -> Result<(), PushProfileError> {
291291
let ssh_opts_str = data
292292
.deploy_data
293293
.merged_settings

0 commit comments

Comments
 (0)