@@ -473,21 +473,26 @@ export function startBuild(data: any, buildConfig?: any): Promise<any> {
473473 . then ( bdata => buildData = bdata )
474474 . then ( ( ) => sendPendingStatus ( buildData , buildData . id ) )
475475 . then ( ( ) => {
476- return Promise . all ( config . map ( cfg => {
477- let dataJob = null ;
478- return dbJob . insertJob ( { data : JSON . stringify ( cfg ) , builds_id : data . build_id } )
479- . then ( job => dataJob = job )
480- . then ( ( ) => getLastRunId ( data . build_id ) )
481- . then ( lastRunId => {
482- let jobRun = {
483- start_time : new Date ,
484- status : 'queued' ,
485- build_run_id : lastRunId ,
486- job_id : dataJob . id
487- } ;
488- return dbJobRuns . insertJobRun ( jobRun ) ;
489- } ) . then ( ( ) => queueJob ( dataJob . id ) ) ;
490- } ) ) ;
476+ return config . reduce ( ( prev , cfg , i ) => {
477+ return prev . then ( ( ) => {
478+ let dataJob = null ;
479+
480+ return dbJob . insertJob ( { data : JSON . stringify ( cfg ) , builds_id : data . build_id } )
481+ . then ( job => dataJob = job )
482+ . then ( ( ) => getLastRunId ( data . build_id ) )
483+ . then ( lastRunId => {
484+ const jobRun = {
485+ start_time : new Date ,
486+ status : 'queued' ,
487+ build_run_id : lastRunId ,
488+ job_id : dataJob . id
489+ } ;
490+
491+ return dbJobRuns . insertJobRun ( jobRun ) ;
492+ } )
493+ . then ( ( ) => queueJob ( dataJob . id ) ) ;
494+ } ) ;
495+ } , Promise . resolve ( ) ) ;
491496 } )
492497 . then ( lastBuild => {
493498 jobEvents . next ( {
@@ -539,7 +544,11 @@ export function restartBuild(buildId: number): Promise<any> {
539544 } ) ) ;
540545 } )
541546 . then ( ( ) => {
542- return Promise . all ( jobs . map ( job => stopJob ( job . id ) . then ( ( ) => queueJob ( job . id ) ) ) ) ;
547+ return jobs . reduce ( ( prev , curr ) => {
548+ return prev . then ( ( ) => {
549+ return stopJob ( curr . id ) . then ( ( ) => queueJob ( curr . id ) ) ;
550+ } ) ;
551+ } , Promise . resolve ( ) ) ;
543552 } )
544553 . then ( ( ) => getBuild ( buildId ) )
545554 . then ( build => sendPendingStatus ( build , build . id ) )
@@ -563,7 +572,11 @@ export function restartBuild(buildId: number): Promise<any> {
563572
564573export function stopBuild ( buildId : number ) : Promise < any > {
565574 return getBuild ( buildId )
566- . then ( build => Promise . all ( build . jobs . map ( job => stopJob ( job . id ) ) ) )
575+ . then ( build => {
576+ return build . jobs . reduce ( ( prev , current ) => {
577+ return prev . then ( ( ) => stopJob ( current . id ) ) ;
578+ } , Promise . resolve ( ) ) ;
579+ } )
567580 . catch ( err => {
568581 let msg : LogMessageType = { message : `[error]: ${ err } ` , type : 'error' , notify : false } ;
569582 logger . next ( msg ) ;
0 commit comments