File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -157,12 +157,22 @@ export const stats = async () => ({
157157 const browser = await entry . browser ;
158158 try {
159159 const pages = await browser . pages ( ) ;
160+
161+ const pageStats = async ( page ) => ( {
162+ title : await page . title ( ) ,
163+ url : page . url ( ) ,
164+ metrics : await page . metrics ( ) ,
165+ } )
166+
160167 return [ namespace , {
161- pages : await promiseRecursive ( ( pages ) . map ( async ( page ) => ( {
162- title : await page . title ( ) ,
163- url : page . url ( ) ,
164- metrics : await page . metrics ( ) ,
165- } ) ) )
168+ pages : await promiseRecursive ( ( pages ) . map ( ( page ) => {
169+ return timeout ( pageStats ( page ) , 5000 ) . catch ( err => {
170+ // Timeout
171+ console . error ( page . url ( ) , err ) ;
172+ console . log ( "Error duing page stats, so killing page" ) ;
173+ invalidatePage ( namespace , page . url ( ) )
174+ } ) ;
175+ } ) )
166176 } ] ;
167177 } catch ( err ) {
168178 console . error ( err ) ;
@@ -174,6 +184,9 @@ export const stats = async () => ({
174184 }
175185 } ) ;
176186
187+ const timeout = ( prom , time_ms ) =>
188+ Promise . race ( [ prom , new Promise ( ( _r , rej ) => setTimeout ( rej , time_ms ) ) ] ) ;
189+
177190export const statsHandler = async ( req , res ) => {
178191 try {
179192 res . json ( await stats ( ) ) ;
You can’t perform that action at this time.
0 commit comments