Skip to content

Commit 170abe7

Browse files
committed
[cache-bundle-js] Issue #432 Skip collecting cache-bundle data in monitoring mode
1 parent 1a0073a commit 170abe7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

plugins/cache-bundle-js/cache-bundle.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ else if (enableCacheBundle) {
513513
const automationFunctionResultName = '__' + status.serverSecret + '__';
514514
const automationFunctionWrapper = async function automationFunctionWrapper() {
515515
try {
516+
/* @ifndef enableMonitoring */
516517
// clear cache
517518
let automationStatus = JSON.parse(await (await (await caches.open(version)).match(AUTOMATION_PSEUDO_URL)).text());
518519
if (automationStatus.state === 'init') {
@@ -563,6 +564,37 @@ else if (enableCacheBundle) {
563564
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 }}));
564565
//console.log('cache-bundle.js: done');
565566
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 */
566598
}
567599
catch (e) {
568600
//console.log('cache-bundle.js: error ', e);

plugins/cache-bundle-js/configurator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const configurator = function (targetConfig) {
2727
EQUAL: '=',
2828
SEMICOLON: ';',
2929
enableCacheBundle,
30+
enableMonitoring: this.mode.enableMonitoring || undefined, // for @ifdef enableMonitoring
3031
},
3132
{
3233
type: 'js',
@@ -46,6 +47,7 @@ const configurator = function (targetConfig) {
4647
EQUAL: '=',
4748
SEMICOLON: ';',
4849
enableCacheBundle,
50+
enableMonitoring: this.mode.enableMonitoring || undefined, // for @ifdef enableMonitoring
4951
},
5052
{
5153
type: 'js',

0 commit comments

Comments
 (0)