@@ -656,54 +656,71 @@ function deployTrigger(event, funcName, namespace, service, options) {
656
656
}
657
657
658
658
function deploy ( functions , runtime , service , options ) {
659
- const errors = [ ] ;
660
- let counter = 0 ;
659
+ // Concurrents deploys to execute
660
+ const deployConcurrency = process . env . DEPLOY_CONCURRENCY || Number . MAX_VALUE ;
661
+
662
+ return new BbPromise ( ( deployResolve , deployReject ) => {
663
+ const deployQueue = functions . slice ( ) ;
664
+
665
+ const deployFunctions = ( functionsToDeploy ) => new BbPromise ( ( resolve , reject ) => {
666
+ const errors = [ ] ;
667
+ let counter = 0 ;
668
+ // Total number of elements to deploy for this iteration
669
+ const elements = helpers . getDeployableItemsNumber ( functionsToDeploy ) ;
670
+ _ . each ( functionsToDeploy , ( description ) => {
671
+ const opts = _ . defaults ( { } , options , {
672
+ hostname : null ,
673
+ namespace : 'default' ,
674
+ memorySize : null ,
675
+ force : false ,
676
+ verbose : false ,
677
+ log : console . log ,
678
+ contentType : ( 'contentType' in description ) ? description . contentType : 'text' ,
679
+ labels : description . labels || { } ,
680
+ } ) ;
661
681
662
- // Total number of elements to deploy
663
- const elements = helpers . getDeployableItemsNumber ( functions ) ;
664
- return new BbPromise ( ( resolve , reject ) => {
665
- _ . each ( functions , ( description ) => {
666
- const opts = _ . defaults ( { } , options , {
667
- hostname : null ,
668
- namespace : 'default' ,
669
- memorySize : null ,
670
- force : false ,
671
- verbose : false ,
672
- log : console . log ,
673
- contentType : ( 'contentType' in description ) ? description . contentType : 'text' ,
674
- labels : description . labels || { } ,
682
+ const ns = description . namespace || opts . namespace ;
683
+ if ( description . handler ) {
684
+ deployFunction ( description , ns , runtime , opts . contentType , opts )
685
+ . catch ( deploymentErr => errors . push ( deploymentErr ) )
686
+ . then ( ( res ) => {
687
+ if ( res . code && res . code !== 200 ) {
688
+ errors . push ( res . message ) ;
689
+ }
690
+ _ . each ( description . events , event => {
691
+ deployTrigger ( event , description . id , ns , service , opts )
692
+ . catch ( triggerErr => errors . push ( triggerErr ) )
693
+ . then ( ( tr ) => {
694
+ if ( tr && tr . code && tr . code !== 200 ) {
695
+ errors . push ( tr . message ) ;
696
+ }
697
+ counter ++ ;
698
+ helpers . checkFinished ( counter , elements , errors , resolve , reject ) ;
699
+ } ) ;
700
+ } ) ;
701
+ counter ++ ;
702
+ helpers . checkFinished ( counter , elements , errors , resolve , reject ) ;
703
+ } ) ;
704
+ } else {
705
+ counter ++ ;
706
+ opts . log (
707
+ `Skipping deployment of ${ description . id } since it doesn't have a handler`
708
+ ) ;
709
+ helpers . checkFinished ( counter , elements , errors , resolve , reject ) ;
710
+ }
675
711
} ) ;
712
+ } ) ;
676
713
677
- const ns = description . namespace || opts . namespace ;
678
- if ( description . handler ) {
679
- deployFunction ( description , ns , runtime , opts . contentType , opts )
680
- . catch ( deploymentErr => errors . push ( deploymentErr ) )
681
- . then ( ( res ) => {
682
- if ( res . code && res . code !== 200 ) {
683
- errors . push ( res . message ) ;
684
- }
685
- _ . each ( description . events , event => {
686
- deployTrigger ( event , description . id , ns , service , opts )
687
- . catch ( triggerErr => errors . push ( triggerErr ) )
688
- . then ( ( tr ) => {
689
- if ( tr && tr . code && tr . code !== 200 ) {
690
- errors . push ( tr . message ) ;
691
- }
692
- counter ++ ;
693
- helpers . checkFinished ( counter , elements , errors , resolve , reject ) ;
694
- } ) ;
695
- } ) ;
696
- counter ++ ;
697
- helpers . checkFinished ( counter , elements , errors , resolve , reject ) ;
698
- } ) ;
714
+ const nextDeploy = ( ) => {
715
+ if ( deployQueue . length > 0 ) {
716
+ const functionsToDeploy = deployQueue . splice ( 0 , deployConcurrency ) ;
717
+ deployFunctions ( functionsToDeploy ) . then ( ( ) => nextDeploy ( ) ) . catch ( ( ex ) => deployReject ( ex ) ) ;
699
718
} else {
700
- counter ++ ;
701
- opts . log (
702
- `Skipping deployment of ${ description . id } since it doesn't have a handler`
703
- ) ;
704
- helpers . checkFinished ( counter , elements , errors , resolve , reject ) ;
719
+ deployResolve ( ) ;
705
720
}
706
- } ) ;
721
+ } ;
722
+
723
+ nextDeploy ( ) ;
707
724
} ) ;
708
725
}
709
726
0 commit comments