From 5a97e5bd64ae13bb66affa244b08b29c5001acc0 Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Mon, 26 Feb 2024 17:46:56 -0600 Subject: [PATCH] Safely reduce verbosity (famous last words) --- types/filesystem.js | 20 +++++++++++++++++--- types/service.js | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/types/filesystem.js b/types/filesystem.js index 7b8446fd6..958734f47 100644 --- a/types/filesystem.js +++ b/types/filesystem.js @@ -35,7 +35,8 @@ class Filesystem extends Actor { this._state = { actors: {}, content: { - files: [] + files: [], + status: 'INITIALIZED' }, documents: {} }; @@ -128,11 +129,23 @@ class Filesystem extends Actor { fs.writeFileSync(file, content); return true; } catch (exception) { - this.emit('error', `Could not write file: ${content}`); + this.emit('error', `Could not write file: ${content} ${exception}`); return false; } } + _handleDiskChange (type, filename) { + this.emit('file:update', { + name: filename, + type: type + }); + + // TODO: only sync changed files + // this._loadFromDisk(); + + return this; + } + /** * Load Filesystem state from disk. * @returns {Promise} Resolves with Filesystem instance. @@ -190,8 +203,9 @@ class Filesystem extends Actor { } async start () { + this._state.content.status = 'STARTING'; this.touchDir(this.path); // ensure exists - await this.sync(); + this.sync(); return this; } diff --git a/types/service.js b/types/service.js index 9f198ba69..b314f288e 100644 --- a/types/service.js +++ b/types/service.js @@ -406,7 +406,7 @@ class Service extends Actor { self.emit('debug', `[FABRIC:SERVICE] Source "${name}" emitted error: ${error}`); }), _handleLog: source.on('log', async function _handleTrustedLog (log) { - self.emit('log', `[FABRIC:SERVICE] Source "${name}" emitted log: ${log}`); + if (self.settings.debug) self.emit('log', `[FABRIC:SERVICE] Source "${name}" emitted log: ${log}`); }), _handleMessage: source.on('message', async function (message) { self.emit('debug', `[FABRIC:SERVICE] Source "${name}" emitted message: ${JSON.stringify(message.toObject ? message.toObject() : message, null, ' ')}`); @@ -424,7 +424,7 @@ class Service extends Actor { self.alert(`[FABRIC:SERVICE] New ${name} chaintip: ${hash}`); }), _handleWarning: source.on('warning', async function _handleTrustedWarning (warning) { - self.emit('warning', `[FABRIC:SERVICE] Source "${name}" emitted warning: ${warning}`); + if (self.settings?.verbosity >= 2) self.emit('warning', `[FABRIC:SERVICE] Source "${name}" emitted warning: ${warning}`); }) }; }