Add timing information
This commit is contained in:
		
							parent
							
								
									3334abb9d8
								
							
						
					
					
						commit
						84665ba267
					
				
							
								
								
									
										3
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								index.js
									
									
									
									
									
								
							| @ -62,6 +62,7 @@ router.get("/", async (ctx) => { | ||||
|           <input type="submit" /> | ||||
|         </form> | ||||
|         <code><pre id="output"></pre></code> | ||||
|         <code><pre id="stdout"></pre></code> | ||||
|       </body> | ||||
|       <script> | ||||
|         async function sleep(time) { | ||||
| @ -79,6 +80,8 @@ router.get("/", async (ctx) => { | ||||
|             response = await (await fetch(\`/api/requests/\${id}\`)).json();
 | ||||
|             console.log(response); | ||||
|             output.innerHTML = JSON.stringify(response, null, "   "); | ||||
|             console.log(response.output); | ||||
|             stdout.innerHTML = response.output; | ||||
|             await sleep(1000); | ||||
|           } while (response.status !== "finished"); | ||||
|         } | ||||
|  | ||||
							
								
								
									
										27
									
								
								request.js
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								request.js
									
									
									
									
									
								
							| @ -13,6 +13,11 @@ module.exports = class ScreenshotRequest { | ||||
|     this.status = "waiting"; | ||||
|     this.output = ""; | ||||
|     this.images = []; | ||||
|     this.request_time = Date.now(); | ||||
|     this.started_time = null; | ||||
|     this.finished_time = null; | ||||
|     this.processing_took = null; | ||||
|     this.waiting_took = null; | ||||
|     q.push(async () => { | ||||
|       return this.exec(); | ||||
|     }); | ||||
| @ -34,12 +39,30 @@ module.exports = class ScreenshotRequest { | ||||
|       domains: this.domains, | ||||
|       id: this.id, | ||||
|       status: this.status, | ||||
|       /* output: this.output, */ | ||||
|       output: this.output, | ||||
|       files: await this.getImages(), | ||||
|       request_time: this.request_time, | ||||
|       started_time: this.started_time, | ||||
|       finished_time: this.finished_time, | ||||
|       processing_took: this.processing_took, | ||||
|       waiting_took: this.waiting_took, | ||||
|       elapsed_time_s: Math.round( | ||||
|         ((this.status === "finished" ? this.finished_time : Date.now()) - | ||||
|           this.request_time) / | ||||
|           1000 | ||||
|       ), | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
|   setFinished() { | ||||
|     this.status = "finished"; | ||||
|     this.finished_time = Date.now(); | ||||
|     this.processing_took = this.finished_time - this.started_time; | ||||
|     this.waiting_took = this.started_time - this.request_time; | ||||
|   } | ||||
| 
 | ||||
|   async exec() { | ||||
|     this.started_time = Date.now(); | ||||
|     return new Promise((resolve, reject) => { | ||||
|       this.status = "running"; | ||||
|       this.process = spawn( | ||||
| @ -55,7 +78,7 @@ module.exports = class ScreenshotRequest { | ||||
|         { cwd: process.cwd() } | ||||
|       ); | ||||
|       this.process.on("close", (exitCode) => { | ||||
|         this.status = "finished"; | ||||
|         this.setFinished(); | ||||
|         if (exitCode === 0) { | ||||
|           resolve(); | ||||
|         } else { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user