@@ -449,39 +449,50 @@ async function printPdf(req, numOfRetries = 0) {
449449 } ) ;
450450
451451 log . info ( 'printPdf :: starting page load' ) ;
452+ const startTime = Date . now ( ) ;
452453 await page . goto ( url , { waitUntil : 'networkidle0' } ) ;
454+ log . info ( `printPdf :: Page loaded successfully in ${ Date . now ( ) - startTime } ms` ) ;
455+
456+ log . info ( 'printPdf :: Waiting for signature field to appear' ) ;
453457 await page . waitForSelector ( '#signatureTextField' , { visible : true } ) ;
454458
455- log . info ( 'printPdf :: page loaded starting pdf creation' ) ;
459+ log . info ( 'printPdf :: Begin Generating PDF' ) ;
460+ const pdfStartTime = Date . now ( ) ;
456461 const pdfBuffer = await page . pdf ( {
457462 displayHeaderFooter : false ,
458463 printBackground : true ,
459464 timeout : 300000 ,
460465 width : 1280 ,
461466 } ) ;
467+ log . info ( `printPdf :: PDF generated in ${ Date . now ( ) - pdfStartTime } ms` ) ;
462468
463- log . info ( 'printPdf :: pdf buffer created starting compression ' ) ;
469+ log . info ( 'printPdf :: Compressing PDF ' ) ;
464470 const compressedPdfBuffer = await compress ( pdfBuffer , {
465471 gsModule : process . env . GHOSTSCRIPT_PATH , // this is set in dockerfile to fix ghostscript error on deploy
466472 } ) ;
467- log . info ( ' printPdf :: compression completed for applicationId' , req . params . applicationId ) ;
473+ log . info ( ` printPdf :: Compression completed for applicationId= ${ req . params . applicationId } ` ) ;
468474
475+ log . info ( 'printPdf :: Sending PDF to storage' ) ;
469476 const payload = await postPdf ( req , compressedPdfBuffer ) ;
477+
478+ log . info ( `printPdf :: PDF successfully stored for applicationId=${ req . params . applicationId } ` ) ;
470479 await browserContext . close ( ) ;
471480 closeBrowser ( ) ;
472481
473482 return payload ;
474483 } catch ( e ) {
475- log . error ( e ) ;
484+ const errorMessage = e instanceof Error ? e . stack || e . message : JSON . stringify ( e ) ;
485+ log . error ( `printPdf :: Error occurred for applicationId=${ req . params . applicationId } , ${ errorMessage } ` ) ;
486+
476487 await browserContext ?. close ( ) ;
477488
478- if ( numOfRetries >= 3 ) {
479- log . info ( ' printPdf :: maximum number of retries reached' ) ;
480- log . error ( `printPdf :: unable to save pdf for application id ${ req . params . applicationId } ` ) ;
489+ if ( numOfRetries >= 5 ) {
490+ log . error ( ` printPdf :: Maximum retries reached for applicationId= ${ req . params . applicationId } . Aborting.` ) ;
491+ closeBrowser ( ) ;
481492 } else {
482- let retryCount = numOfRetries + 1 ;
483- log . info ( 'printPdf :: failed retrying' ) ;
484- log . info ( `printPdf :: retry count ${ retryCount } ` ) ;
493+ const retryCount = numOfRetries + 1 ;
494+ await sleep ( 5000 ) ;
495+ log . info ( `printPdf :: Retrying ( ${ retryCount } /5) for applicationId= ${ req . params . applicationId } ` ) ;
485496 await printPdf ( req , retryCount ) ;
486497 }
487498 }
0 commit comments