Clean docker containers on sigINT
This commit is contained in:
		
							parent
							
								
									3f6d9c5cad
								
							
						
					
					
						commit
						d06426e22f
					
				| @ -49,6 +49,11 @@ class Container { | ||||
|   close() { | ||||
|     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 { | ||||
| @ -58,6 +63,11 @@ module.exports = new (class ContainerPool { | ||||
|     for (let i = 1; i <= this.concurrency; i++) { | ||||
|       this.generateContainer(); | ||||
|     } | ||||
| 
 | ||||
|     process.on("SIGINT", () => { | ||||
|       console.log("SIGINT"); | ||||
|       this.clear(); | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   generateContainer() { | ||||
| @ -72,4 +82,13 @@ module.exports = new (class ContainerPool { | ||||
|     this.generateContainer(); | ||||
|     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); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user