@@ -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 } ;
@@ -591,17 +592,21 @@ async fn run_deploy(
591
592
data. deploy_data . merged_settings . remote_build . unwrap_or_default ( )
592
593
} ) ;
593
594
594
- // await both the remote builds and the local builds to speed up deployment times
595
+ // the grouping by host will retain each hosts ordering by profiles_order since the fold is synchronous
596
+ let remote_build_map: HashMap < _ , Vec < _ > > = remote_builds. iter ( ) . fold ( HashMap :: new ( ) , |mut accum, elem| {
597
+ match accum. get_mut ( elem. deploy_data . node_name ) {
598
+ Some ( v) => { v. push ( elem) ; accum } ,
599
+ None => { accum. insert ( elem. deploy_data . node_name , vec ! [ elem] ) ; accum }
600
+ }
601
+ } ) ;
602
+
595
603
try_join ! (
596
- // remote builds can be run asynchronously since they do not affect the local machine
597
- try_join_all( remote_builds. into_iter( ) . map( |data| async {
598
- let data = data;
599
- deploy:: push:: build_profile( & data) . await
600
- } ) ) ,
604
+ // remote builds can be run asynchronously (per host)
605
+ try_join_all( remote_build_map. into_iter( ) . map( deploy_profiles_to_host) ) ,
601
606
async {
602
607
// run local builds synchronously to prevent hardware deadlocks
603
608
for data in & local_builds {
604
- deploy:: push:: build_profile( data) . await ? ;
609
+ deploy:: push:: build_profile( data) . await . unwrap ( ) ;
605
610
}
606
611
607
612
// push all profiles asynchronously
@@ -744,3 +749,10 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
744
749
745
750
Ok ( ( ) )
746
751
}
752
+
753
+ async fn deploy_profiles_to_host < ' a > ( ( _host, profiles) : ( & str , Vec < & ' a PushProfileData < ' a > > ) ) -> Result < ( ) , PushProfileError > {
754
+ for profile in & profiles {
755
+ deploy:: push:: build_profile ( profile) . await ?;
756
+ } ;
757
+ Ok ( ( ) )
758
+ }
0 commit comments