Clean docker containers on sigINT
This commit is contained in:
parent
3f6d9c5cad
commit
d06426e22f
|
@ -49,6 +49,11 @@ class Container {
|
||||||
close() {
|
close() {
|
||||||
spawn("docker", ["rm", "-f", this.id]);
|
spawn("docker", ["rm", "-f", this.id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeSync() {
|
||||||
|
spawnSync("docker", ["rm", "-f", this.id]);
|
||||||
|
console.log("doker rm done", this.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new (class ContainerPool {
|
module.exports = new (class ContainerPool {
|
||||||
|
@ -58,6 +63,11 @@ module.exports = new (class ContainerPool {
|
||||||
for (let i = 1; i <= this.concurrency; i++) {
|
for (let i = 1; i <= this.concurrency; i++) {
|
||||||
this.generateContainer();
|
this.generateContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.on("SIGINT", () => {
|
||||||
|
console.log("SIGINT");
|
||||||
|
this.clear();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generateContainer() {
|
generateContainer() {
|
||||||
|
@ -72,4 +82,13 @@ module.exports = new (class ContainerPool {
|
||||||
this.generateContainer();
|
this.generateContainer();
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
console.log("Removing all containers from the pool");
|
||||||
|
for (const container of this.pool) {
|
||||||
|
container.closeSync();
|
||||||
|
}
|
||||||
|
console.log("Removing containers done");
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
})(concurrency);
|
})(concurrency);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user