Skip to content

Commit

Permalink
fix(builds): return job failed status correctly, cleanup docker conta…
Browse files Browse the repository at this point in the history
…iners
  • Loading branch information
jkuri committed Sep 24, 2017
1 parent 0f87888 commit ae5b740
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
15 changes: 3 additions & 12 deletions src/api/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,10 @@ export function killContainer(id: string): Promise<void> {
container = docker.getContainer(id);
container.inspect()
.then(containerInfo => {
if (containerInfo.State.Running) {
return container.kill()
.then(() => container.inspect())
.then(info => info.State.Status);
if (containerInfo.State.Status === 'running') {
return container.kill().then(() => container.remove());
} else {
return Promise.resolve(containerInfo.State.Status)
.then(status => {
if (status === 'exited') {
return container.remove();
} else {
return Promise.resolve();
}
});
return Promise.resolve();
}
})
.then(() => resolve())
Expand Down
16 changes: 16 additions & 0 deletions src/api/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ function execJob(proc: JobProcess): Observable<{}> {
additionalData: time.getTime()
});
})
.then(() => {
jobEvents.next({
type: 'process',
build_id: proc.build_id,
job_id: proc.job_id,
data: 'job failed'
});
})
.then(() => observer.complete())
.catch(err => {
const msg: LogMessageType = {
Expand Down Expand Up @@ -233,6 +241,14 @@ function execJob(proc: JobProcess): Observable<{}> {
message: `[error]: ${err}`, type: 'error', notify: false
};
logger.next(msg);

jobEvents.next({
type: 'process',
build_id: proc.build_id,
job_id: proc.job_id,
data: 'job failed'
});

observer.complete();
});
});
Expand Down
10 changes: 6 additions & 4 deletions src/api/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ export function startBuildProcess(
].join(' ');
const tmsg = `[error]: executed command returned exit code ${event.data}`;
observer.next({ type: 'exit', data: red(tmsg) });
sub.unsubscribe();
observer.error(msg);
docker.killContainer(name)
.then(() => observer.complete())
.then(() => {
sub.unsubscribe();
observer.complete();
})
.catch(err => console.error(err));
}
} else {
Expand All @@ -137,17 +139,17 @@ export function startBuildProcess(
observer.error(err);
docker.killContainer(name)
.then(() => {
observer.complete();
sub.unsubscribe();
observer.complete();
})
.catch(err => console.error(err));
}, () => {
const msg = '[success]: build returned exit code 0';
observer.next({ type: 'exit', data: green(msg) });
docker.killContainer(name)
.then(() => {
observer.complete();
sub.unsubscribe();
observer.complete();
})
.catch(err => console.error(err));
});
Expand Down

0 comments on commit ae5b740

Please sign in to comment.