Permalink
Browse files

fix(): fixed sending commit status

  • Loading branch information...
Izak88 committed Aug 31, 2017
1 parent ba6c5fa commit 66cb7f2d8de826ba9bd5de886eb8930957f23f88
Showing with 49 additions and 9 deletions.
  1. +15 −2 src/api/db/build.ts
  2. +34 −7 src/api/process-manager.ts
@@ -226,8 +226,21 @@ export function getBuildStatus(buildId: number): Promise<any> {
.query(q => q.where('builds_id', buildId))
.fetchAll()
.then(jobs => {
Promise.all(jobs.map(j => getLastRun(j.id).then(r => r.status === 'success')))
.then(data => resolve(data.reduce((curr, prev) => !curr ? curr : prev)));
Promise.all(jobs.map(j => getLastRun(j.id).then(r => r.status)))
.then(data => resolve(data.reduce((accu, curr) => {
if (curr === 'queued') {
return curr;
} else if (curr === 'running' && accu !== 'queued') {
return curr;
} else if (curr === 'failed' && accu !== 'running' && accu !== 'queued') {
return curr;
} else if (curr === 'success' && accu !== 'failed'
&& accu !== 'running' && accu !== 'queued') {
return curr;
}

return accu;
})));
});
});
}
@@ -271,9 +271,11 @@ export function startJob(p: JobProcess): Promise<void> {
job_id: p.job_id,
data: 'jobFailed'
});

if (processes.findIndex(proc => proc.build_id === p.build_id) === -1) {
getBuild(p.build_id).then(build => sendFailureStatus(build, build.id));
}
})
.then(() => getBuild(p.build_id))
.then(build => sendFailureStatus(build, build.id))
.catch(err => logger.error(err));
}, () => {
dbJob.getLastRunId(p.job_id)
@@ -289,13 +291,16 @@ export function startJob(p: JobProcess): Promise<void> {
})
.then(() => getBuildStatus(p.build_id))
.then(status => {
if (status) {
if (status === 'success') {
return updateBuild({ id: p.build_id, end_time: new Date() })
.then(() => getLastRunId(p.build_id))
.then(id => updateBuildRun({ id: id, end_time: new Date()} ))
.then(() => getBuild(p.build_id))
.then(build => sendSuccessStatus(build, build.id))
.catch(err => logger.error(err));
} else if (status === 'failed') {
getBuild(p.build_id)
.then(build => sendFailureStatus(build, build.id));
} else {
return Promise.resolve();
}
@@ -338,12 +343,36 @@ export function stopJob(jobId: number): Promise<any> {
}
})
.then(() => dbJob.getJob(jobId))
.then(job => stopContainer(`abstruse_${job.builds_id}_${job.id}`).toPromise())
.then(job => {
return stopContainer(`abstruse_${job.builds_id}_${jobId}`).toPromise()
.then(() => getBuildStatus(job.builds_id))
.then(status => {
if (status === 'success') {
getBuild(job.builds_id)
.then(build => sendSuccessStatus(build, build.id));
} else if (status === 'failed') {
getBuild(job.builds_id)
.then(build => sendFailureStatus(build, build.id));
}
});
})
.catch(err => logger.error(err));
} else {
return Promise.resolve()
.then(() => dbJob.getJob(jobId))
.then(job => stopContainer(`abstruse_${job.builds_id}_${job.id}`).toPromise())
.then(job => {
return stopContainer(`abstruse_${job.builds_id}_${jobId}`).toPromise()
.then(() => getBuildStatus(job.builds_id))
.then(status => {
if (status === 'success') {
getBuild(job.builds_id)
.then(build => sendSuccessStatus(build, build.id));
} else if (status === 'failed') {
getBuild(job.builds_id)
.then(build => sendFailureStatus(build, build.id));
}
});
})
.then(() => dbJob.getLastRunId(jobId))
.then(runId => dbJobRuns.getRun(runId))
.then(jobRun => {
@@ -456,8 +485,6 @@ export function stopBuild(buildId: number): Promise<any> {
return prev.then(() => stopJob(current.job_id));
}, Promise.resolve()).then(() => procs);
})
.then(() => getBuild(buildId))
.then(buildData => sendFailureStatus(buildData, buildData.id))
.catch(err => logger.error(err));
}

0 comments on commit 66cb7f2

Please sign in to comment.