@@ -7,6 +7,8 @@ use std::collections::HashMap;
7
7
use std:: io:: { stdin, stdout, Write } ;
8
8
9
9
use clap:: { ArgMatches , Clap , FromArgMatches } ;
10
+ use futures_util:: future:: { join_all, try_join_all} ;
11
+ use tokio:: try_join;
10
12
11
13
use crate as deploy;
12
14
@@ -587,19 +589,35 @@ async fn run_deploy(
587
589
)
588
590
} ;
589
591
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
+ } ) ?;
596
620
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
- }
603
621
604
622
let mut succeeded: Vec < ( & deploy:: DeployData , & deploy:: DeployDefs ) > = vec ! [ ] ;
605
623
0 commit comments