From ae5b740b7d96d574e12d29f921662eb1983ee461 Mon Sep 17 00:00:00 2001 From: Jan Kuri Date: Sun, 24 Sep 2017 06:41:26 +0200 Subject: [PATCH] fix(builds): return job failed status correctly, cleanup docker containers --- src/api/docker.ts | 15 +++------------ src/api/process-manager.ts | 16 ++++++++++++++++ src/api/process.ts | 10 ++++++---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/api/docker.ts b/src/api/docker.ts index 9c54e688a..5267fd79e 100644 --- a/src/api/docker.ts +++ b/src/api/docker.ts @@ -166,19 +166,10 @@ export function killContainer(id: string): Promise { 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()) diff --git a/src/api/process-manager.ts b/src/api/process-manager.ts index be1a706e4..ae7e08f77 100644 --- a/src/api/process-manager.ts +++ b/src/api/process-manager.ts @@ -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(); }); }); diff --git a/src/api/process.ts b/src/api/process.ts index 9064b0879..0455d03cd 100644 --- a/src/api/process.ts +++ b/src/api/process.ts @@ -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,8 +139,8 @@ export function startBuildProcess( observer.error(err); docker.killContainer(name) .then(() => { - observer.complete(); sub.unsubscribe(); + observer.complete(); }) .catch(err => console.error(err)); }, () => { @@ -146,8 +148,8 @@ export function startBuildProcess( observer.next({ type: 'exit', data: green(msg) }); docker.killContainer(name) .then(() => { - observer.complete(); sub.unsubscribe(); + observer.complete(); }) .catch(err => console.error(err)); });