@@ -11,6 +11,7 @@ use futures_util::future::{join_all, try_join_all};
11
11
use tokio:: try_join;
12
12
13
13
use crate as deploy;
14
+ use crate :: push:: { PushProfileData , PushProfileError } ;
14
15
15
16
use self :: deploy:: { DeployFlake , ParseFlakeError } ;
16
17
use futures_util:: stream:: { StreamExt , TryStreamExt } ;
@@ -593,17 +594,21 @@ async fn run_deploy(
593
594
data. deploy_data . merged_settings . remote_build . unwrap_or_default ( )
594
595
} ) ;
595
596
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
+
597
605
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) ) ,
603
608
async {
604
609
// run local builds synchronously to prevent hardware deadlocks
605
610
for data in & local_builds {
606
- deploy:: push:: build_profile( data) . await ? ;
611
+ deploy:: push:: build_profile( data) . await . unwrap ( ) ;
607
612
}
608
613
609
614
@@ -750,3 +755,10 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
750
755
751
756
Ok ( ( ) )
752
757
}
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