Permalink
Browse files

fix(builds): return job failed status correctly, cleanup docker conta…

…iners
  • Loading branch information...
jkuri committed Sep 24, 2017
1 parent 0f87888 commit ae5b740b7d96d574e12d29f921662eb1983ee461
Showing with 25 additions and 16 deletions.
  1. +3 −12 src/api/docker.ts
  2. +16 −0 src/api/process-manager.ts
  3. +6 −4 src/api/process.ts
@@ -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())
@@ -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 = {
@@ -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();
});
});
@@ -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 {
@@ -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));
});

0 comments on commit ae5b740

Please sign in to comment.