Permalink
Browse files

perf(kill-container): swithc from observable to promise when killing …

…docker container
  • Loading branch information...
jkuri committed Aug 3, 2017
1 parent a23acf3 commit d37a8374cf92f631d99337191a84a0a4c8f6397c
Showing with 6 additions and 9 deletions.
  1. +4 −7 src/api/docker.ts
  2. +2 −2 src/api/process-manager.ts
@@ -44,13 +44,10 @@ export function killAllContainers(): Observable<boolean> {
});
}

export function killContainer(id: string): Observable<boolean> {
return new Observable(observer => {
const kill = spawn('docker', ['rm', id, '-f']);
kill.on('close', code => {
observer.next();
observer.complete();
});
export function killContainer(id: string): Promise<void> {
return new Promise(resolve => {
const kill = pty.spawn('docker', ['rm', id, '-f']);
kill.on('exit', code => resolve());
});
}

@@ -385,7 +385,7 @@ export function stopJob(jobId: number): Promise<any> {
dbJob.updateJob({ id: jobId, end_time: new Date(), status: 'failed', log: log })
.then(() => {
const name = `abstruse_${jobProcess.build_id}_${jobProcess.job_id}`;
return killContainer(name).toPromise();
return killContainer(name);
})
.then(() => resolve(jobProcess));
} else {
@@ -402,7 +402,7 @@ export function stopJob(jobId: number): Promise<any> {
})
.then(() => {
const name = `abstruse_${job.builds_id}_${job.id}`;
return killContainer(name).toPromise();
return killContainer(name);
})
.then(() => resolve(job));
}

0 comments on commit d37a837

Please sign in to comment.