Skip to content

Commit d37a837

Browse files
committed
perf(kill-container): swithc from observable to promise when killing docker container
1 parent a23acf3 commit d37a837

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/api/docker.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ export function killAllContainers(): Observable<boolean> {
4444
});
4545
}
4646

47-
export function killContainer(id: string): Observable<boolean> {
48-
return new Observable(observer => {
49-
const kill = spawn('docker', ['rm', id, '-f']);
50-
kill.on('close', code => {
51-
observer.next();
52-
observer.complete();
53-
});
47+
export function killContainer(id: string): Promise<void> {
48+
return new Promise(resolve => {
49+
const kill = pty.spawn('docker', ['rm', id, '-f']);
50+
kill.on('exit', code => resolve());
5451
});
5552
}
5653

src/api/process-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export function stopJob(jobId: number): Promise<any> {
385385
dbJob.updateJob({ id: jobId, end_time: new Date(), status: 'failed', log: log })
386386
.then(() => {
387387
const name = `abstruse_${jobProcess.build_id}_${jobProcess.job_id}`;
388-
return killContainer(name).toPromise();
388+
return killContainer(name);
389389
})
390390
.then(() => resolve(jobProcess));
391391
} else {
@@ -402,7 +402,7 @@ export function stopJob(jobId: number): Promise<any> {
402402
})
403403
.then(() => {
404404
const name = `abstruse_${job.builds_id}_${job.id}`;
405-
return killContainer(name).toPromise();
405+
return killContainer(name);
406406
})
407407
.then(() => resolve(job));
408408
}

0 commit comments

Comments
 (0)