@@ -11,6 +11,7 @@ use futures_util::future::{join_all, try_join_all};
1111use tokio:: try_join;
1212
1313use crate as deploy;
14+ use crate :: push:: { PushProfileData , PushProfileError } ;
1415
1516use self :: deploy:: { DeployFlake , ParseFlakeError } ;
1617use futures_util:: stream:: { StreamExt , TryStreamExt } ;
@@ -591,17 +592,21 @@ async fn run_deploy(
591592 data. deploy_data . merged_settings . remote_build . unwrap_or_default ( )
592593 } ) ;
593594
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+
595603 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) ) ,
601606 async {
602607 // run local builds synchronously to prevent hardware deadlocks
603608 for data in & local_builds {
604- deploy:: push:: build_profile( data) . await ? ;
609+ deploy:: push:: build_profile( data) . await . unwrap ( ) ;
605610 }
606611
607612 // push all profiles asynchronously
@@ -744,3 +749,10 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
744749
745750 Ok ( ( ) )
746751}
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