Skip to content

Commit

Permalink
Added verbose messages for onFile / offFile
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Jun 21, 2024
1 parent 7c3e667 commit 01d2436
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,8 @@ function sandBox(script, name, verbose, debug, context) {

sandbox.__engine.__subscriptionsFile += 1;

sandbox.verbose && sandbox.log(`onFile(id=${id}, fileNamePattern=${fileNamePattern}) - fileSubscriptions=${sandbox.__engine.__subscriptionsFile}`, 'info');

if (sandbox.__engine.__subscriptionsFile % adapter.config.maxTriggersPerScript === 0) {
sandbox.log(`More than ${sandbox.__engine.__subscriptionsFile} file subscriptions registered. Check your script!`, 'warn');
}
Expand Down Expand Up @@ -1659,10 +1661,12 @@ function sandBox(script, name, verbose, debug, context) {
},
offFile: function (idOrObject, fileNamePattern) {
if (!adapter.unsubscribeForeignFiles) {
sandbox.log('onFile: your js-controller does not support yet offFile unsubscribes. Please update to [email protected] or newer', 'warn');
sandbox.log('offFile: your js-controller does not support yet file unsubscribes. Please update to [email protected] or newer', 'warn');
return;
}

sandbox.verbose && sandbox.log(`offFile(idOrObject=${JSON.stringify(idOrObject)}, fileNamePattern=${fileNamePattern}) - fileSubscriptions=${sandbox.__engine.__subscriptionsFile}`, 'info');

if (idOrObject && typeof idOrObject === 'object') {
if (Array.isArray(idOrObject)) {
const result = [];
Expand All @@ -1674,6 +1678,9 @@ function sandBox(script, name, verbose, debug, context) {
for (let i = context.subscriptionsFile.length - 1; i >= 0; i--) {
if (context.subscriptionsFile[i] === idOrObject) {
unsubscribeFile(script, context.subscriptionsFile[i].id, context.subscriptionsFile[i].fileNamePattern);

sandbox.verbose && sandbox.log(`offFile(type=object, fileNamePattern=${fileNamePattern}, removing id=${context.subscriptionsFile[i].id})`, 'info');

context.subscriptionsFile.splice(i, 1);
sandbox.__engine.__subscriptionsFile--;
return true;
Expand All @@ -1686,6 +1693,9 @@ function sandBox(script, name, verbose, debug, context) {
if (context.subscriptionsFile[i].id === idOrObject && context.subscriptionsFile[i].fileNamePattern === fileNamePattern) {
deleted++;
unsubscribeFile(script, context.subscriptionsFile[i].id, context.subscriptionsFile[i].fileNamePattern);

sandbox.verbose && sandbox.log(`offFile(type=string, fileNamePattern=${fileNamePattern}, removing id=${context.subscriptionsFile[i].id})`, 'info');

context.subscriptionsFile.splice(i, 1);
sandbox.__engine.__subscriptionsFile--;
}
Expand Down

0 comments on commit 01d2436

Please sign in to comment.