mirror of
				https://codeberg.org/ashley/poke
				synced 2025-07-17 16:52:11 +00:00 
			
		
		
		
	add toobusy
This commit is contained in:
		
							parent
							
								
									575db38a3a
								
							
						
					
					
						commit
						d495b26307
					
				
							
								
								
									
										20
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								server.js
									
									
									
									
									
								
							| @ -77,6 +77,7 @@ | |||||||
|   app.use(modules.useragent.express()); |   app.use(modules.useragent.express()); | ||||||
|   app.use(modules.express.json()); // for parsing application/json
 |   app.use(modules.express.json()); // for parsing application/json
 | ||||||
|   app.enable("trust proxy"); |   app.enable("trust proxy"); | ||||||
|  |   var toobusy = require('toobusy-js') | ||||||
| 
 | 
 | ||||||
|   const renderTemplate = async (res, req, template, data = {}) => { |   const renderTemplate = async (res, req, template, data = {}) => { | ||||||
|     res.render( |     res.render( | ||||||
| @ -85,6 +86,25 @@ | |||||||
|     ); |     ); | ||||||
|   }; |   }; | ||||||
|    |    | ||||||
|  |  // Set check interval to a faster value. This will catch more latency spikes
 | ||||||
|  | // but may cause the check to be too sensitive.
 | ||||||
|  | toobusy.interval(110); | ||||||
|  | 
 | ||||||
|  | toobusy.maxLag(2500); | ||||||
|  |    | ||||||
|  |   app.use(function(req, res, next) { | ||||||
|  |   if (toobusy()) { | ||||||
|  |     res.send(503, "I'm busy right now, sorry."); | ||||||
|  |   } else { | ||||||
|  |     next(); | ||||||
|  |   } | ||||||
|  | }); | ||||||
|  |    | ||||||
|  |   toobusy.onLag(function(currentLag) { | ||||||
|  |   console.log("Event loop lag detected! Latency: " + currentLag + "ms"); | ||||||
|  | }); | ||||||
|  |    | ||||||
|  | 
 | ||||||
|   const random_words = [ |   const random_words = [ | ||||||
|     "banana pie", |     "banana pie", | ||||||
|     "how to buy an atom bomb", |     "how to buy an atom bomb", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ashley
						Ashley