@@ -513,6 +513,7 @@ else if (enableCacheBundle) {
513
513
const automationFunctionResultName = '__' + status . serverSecret + '__' ;
514
514
const automationFunctionWrapper = async function automationFunctionWrapper ( ) {
515
515
try {
516
+ /* @ifndef enableMonitoring */
516
517
// clear cache
517
518
let automationStatus = JSON . parse ( await ( await ( await caches . open ( version ) ) . match ( AUTOMATION_PSEUDO_URL ) ) . text ( ) ) ;
518
519
if ( automationStatus . state === 'init' ) {
@@ -563,6 +564,37 @@ else if (enableCacheBundle) {
563
564
await ( await caches . open ( version ) ) . put ( new Request ( AUTOMATION_PSEUDO_URL ) , new Response ( JSON . stringify ( automationStatus ) , { headers : { 'Content-Type' : 'application/json' , 'User-Agent' : navigator . userAgent } } ) ) ;
564
565
//console.log('cache-bundle.js: done');
565
566
return result ;
567
+ /* @endif */
568
+ /* @ifdef enableMonitoring */
569
+ // automate navigation for monitoring
570
+ console . log ( 'cache-bundle.js: calling automationFunction()' ) ;
571
+ await automationFunction ( ) ;
572
+ //console.log('cache-bundle.js: automationFunction() exited');
573
+ await ( await caches . open ( version ) ) . put ( new Request ( AUTOMATION_PSEUDO_URL ) , new Response ( JSON . stringify ( status ) , { headers : { 'Content-Type' : 'application/json' , 'User-Agent' : navigator . userAgent } } ) ) ;
574
+ switch ( status . state ) {
575
+ case 'cleaning' :
576
+ {
577
+ let cache = await caches . open ( version ) ;
578
+ let keys = await cache . keys ( ) ;
579
+ for ( let key of keys ) {
580
+ if ( key . url . startsWith ( PSEUDO_URL_PREFIX ) ) {
581
+ continue ;
582
+ }
583
+ await cache . delete ( key ) ;
584
+ }
585
+ status . state = 'cleaned' ;
586
+ console . log ( 'cache-bundle.js: cleaned caches' ) ;
587
+ await ( await caches . open ( version ) ) . put ( new Request ( AUTOMATION_PSEUDO_URL ) , new Response ( JSON . stringify ( status ) , { headers : { 'Content-Type' : 'application/json' , 'User-Agent' : navigator . userAgent } } ) ) ;
588
+ //await new Promise(resolve => setTimeout(resolve, 5000));
589
+ location . reload ( ) ;
590
+ }
591
+ break ;
592
+ default :
593
+ break ;
594
+ }
595
+ //console.log('cache-bundle.js: done');
596
+ return null ;
597
+ /* @endif */
566
598
}
567
599
catch ( e ) {
568
600
//console.log('cache-bundle.js: error ', e);
0 commit comments