@@ -147,25 +147,30 @@ export function startBuild(data: any): Promise<any> {
147147 builds_id : build . id
148148 } ;
149149
150- return dbJob . insertJob ( jobData ) . then ( job => {
151- const jobRunData = {
152- start_time : new Date ( ) ,
153- end_time : null ,
154- status : 'queued' ,
155- log : '' ,
156- job_id : job . id
157- } ;
158- return dbJobRuns . insertJobRun ( jobRunData ) . then ( ( ) => {
159- jobEvents . next ( {
160- type : 'process' ,
161- build_id : build . id ,
162- job_id : job . id ,
163- data : 'jobAdded'
150+ return dbJob . insertJob ( jobData )
151+ . then ( job => {
152+ getLastRunId ( build . id ) . then ( buildRunId => {
153+ const jobRunData = {
154+ start_time : new Date ( ) ,
155+ end_time : null ,
156+ status : 'queued' ,
157+ log : '' ,
158+ build_run_id : buildRunId ,
159+ job_id : job . id
160+ } ;
161+
162+ return dbJobRuns . insertJobRun ( jobRunData ) . then ( ( ) => {
163+ jobEvents . next ( {
164+ type : 'process' ,
165+ build_id : build . id ,
166+ job_id : job . id ,
167+ data : 'jobAdded'
168+ } ) ;
169+
170+ return queueJob ( build . id , job . id ) ;
171+ } ) ;
164172 } ) ;
165-
166- return queueJob ( build . id , job . id ) ;
167173 } ) ;
168- } ) ;
169174 } ) ;
170175 } , Promise . resolve ( ) ) ;
171176 } ) ;
@@ -356,10 +361,22 @@ export function restartBuild(buildId: number): Promise<any> {
356361
357362 return updateBuild ( build )
358363 . then ( ( ) => {
359- jobs . forEach ( job => {
360- dbJobRuns . insertJobRun (
361- { start_time : new Date ( ) , end_time : null , status : 'queued' , log : '' , job_id : job . id }
362- ) ;
364+ build . build_id = buildId ;
365+ delete build . repositories_id ;
366+ delete build . jobs ;
367+ insertBuildRun ( build ) ;
368+ } )
369+ . then ( ( ) => getLastRunId ( build . id ) )
370+ . then ( buildRunId => {
371+ return jobs . forEach ( job => {
372+ dbJobRuns . insertJobRun ( {
373+ start_time : new Date ( ) ,
374+ end_time : null ,
375+ status : 'queued' ,
376+ log : '' ,
377+ build_run_id : buildRunId ,
378+ job_id : job . id
379+ } ) ;
363380 } ) ;
364381 } )
365382 . then ( ( ) => {
@@ -382,8 +399,14 @@ export function stopBuild(buildId: number): Promise<any> {
382399export function restartJob ( jobId : number ) : Promise < void > {
383400 let jobData = null ;
384401 return stopJob ( jobId )
385- . then ( ( ) => dbJobRuns . insertJobRun (
386- { start_time : new Date ( ) , end_time : null , status : 'queued' , log : '' , job_id : jobId } ) )
402+ . then ( ( ) => dbJob . getLastRun ( jobId ) )
403+ . then ( lastRun => dbJobRuns . insertJobRun ( {
404+ start_time : new Date ( ) ,
405+ end_time : null ,
406+ status : 'queued' ,
407+ log : '' ,
408+ build_run_id : lastRun . build_run_id ,
409+ job_id : jobId } ) )
387410 . then ( job => jobData = job )
388411 . then ( ( ) => queueJob ( jobData . builds_id , jobId ) )
389412 . then ( ( ) => {
@@ -399,8 +422,14 @@ export function restartJob(jobId: number): Promise<void> {
399422export function restartJobWithSshAndVnc ( jobId : number ) : Promise < void > {
400423 let jobData = null ;
401424 return stopJob ( jobId )
402- . then ( ( ) => dbJobRuns . insertJobRun (
403- { start_time : new Date ( ) , end_time : null , status : 'queued' , log : '' , job_id : jobId } ) )
425+ . then ( ( ) => dbJob . getLastRun ( jobId ) )
426+ . then ( lastRun => dbJobRuns . insertJobRun ( {
427+ start_time : new Date ( ) ,
428+ end_time : null ,
429+ status : 'queued' ,
430+ log : '' ,
431+ build_run_id : lastRun . build_run_id ,
432+ job_id : jobId } ) )
404433 . then ( job => jobData = job )
405434 . then ( ( ) => queueJob ( jobData . builds_id , jobId , true ) )
406435 . then ( ( ) => {
0 commit comments