Skip to content

Commit

Permalink
perf(kill-container): swithc from observable to promise when killing …
Browse files Browse the repository at this point in the history
…docker container
  • Loading branch information
jkuri committed Aug 4, 2017
1 parent a23acf3 commit d37a837
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/api/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
Expand Down

0 comments on commit d37a837

Please sign in to comment.