From b3b3f0eb5e187646c6502a9d36939e05c80b5939 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 8 Nov 2023 16:18:19 +0100 Subject: [PATCH] fix: disable dynamic reload until spurious file change is identified MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 3 +- src/charging-station/ChargingStation.ts | 89 ++++++++++++++----------- src/charging-station/IdTagsCache.ts | 61 ++++++++--------- src/utils/Configuration.ts | 7 +- 4 files changed, 86 insertions(+), 74 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 0dbf9510..465d5bf2 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -99,8 +99,7 @@ export class Bootstrap extends EventEmitter { performanceStorageConfiguration.uri!, this.logPrefix(), )); - // FIXME: Disabled until the spurious configuration file change detection on MacOS is identified - // Configuration.configurationChangeCallback = async () => Bootstrap.getInstance().restart(false); + Configuration.configurationChangeCallback = async () => Bootstrap.getInstance().restart(false); } public static getInstance(): Bootstrap { diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 996b9cf9..bd3fb812 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -149,7 +149,7 @@ import { roundTo, secureRandom, sleep, - watchJsonFile, + // watchJsonFile, } from '../utils'; export class ChargingStation { @@ -664,44 +664,55 @@ export class ChargingStation { } this.openWSConnection(); // Monitor charging station template file - this.templateFileWatcher = watchJsonFile( - this.templateFile, - FileType.ChargingStationTemplate, - this.logPrefix(), - undefined, - (event, filename): void => { - if (isNotEmptyString(filename) && event === 'change') { - try { - logger.debug( - `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${ - this.templateFile - } file have changed, reload`, - ); - this.sharedLRUCache.deleteChargingStationTemplate(this.templateFileHash); - // Initialize - this.initialize(); - this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo)!); - // Restart the ATG - this.stopAutomaticTransactionGenerator().catch(() => {}); - delete this.automaticTransactionGeneratorConfiguration; - if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) { - this.startAutomaticTransactionGenerator(); - } - if (this.getEnableStatistics() === true) { - this.performanceStatistics?.restart(); - } else { - this.performanceStatistics?.stop(); - } - // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed - } catch (error) { - logger.error( - `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`, - error, - ); - } - } - }, - ); + // FIXME: Disabled until the spurious configuration file change detection is identified + // this.templateFileWatcher = watchJsonFile( + // this.templateFile, + // FileType.ChargingStationTemplate, + // this.logPrefix(), + // undefined, + // (event, filename): void => { + // if (isNotEmptyString(filename) && event === 'change') { + // try { + // logger.debug( + // `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${ + // this.templateFile + // } file have changed, reload`, + // ); + // this.sharedLRUCache.deleteChargingStationTemplate(this.templateFileHash); + // // Initialize + // this.initialize(); + // this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo)!); + // // Restart the ATG + // this.stopAutomaticTransactionGenerator() + // .then(() => { + // delete this.automaticTransactionGeneratorConfiguration; + // if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) { + // this.startAutomaticTransactionGenerator(); + // } + // }) + // .catch((err) => + // logger.error( + // `${this.logPrefix()} failed to stop ATG at ${ + // FileType.ChargingStationTemplate + // } reload`, + // err, + // ), + // ); + // if (this.getEnableStatistics() === true) { + // this.performanceStatistics?.restart(); + // } else { + // this.performanceStatistics?.stop(); + // } + // // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed + // } catch (error) { + // logger.error( + // `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`, + // error, + // ); + // } + // } + // }, + // ); this.started = true; parentPort?.postMessage(buildStartedMessage(this)); this.starting = false; diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index 5e0ab0b8..5c0a454a 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -7,14 +7,14 @@ import { handleFileException, isNotEmptyString, logPrefix, - logger, + // logger, secureRandom, - watchJsonFile, + // watchJsonFile, } from '../utils'; interface IdTagsCacheValueType { idTags: string[]; - idTagsFileWatcher: FSWatcher | undefined; + idTagsFileWatcher?: FSWatcher | undefined; } export class IdTagsCache { @@ -123,33 +123,34 @@ export class IdTagsCache { private setIdTagsCache(file: string, idTags: string[]) { return this.idTagsCaches.set(file, { idTags, - idTagsFileWatcher: watchJsonFile( - file, - FileType.Authorization, - this.logPrefix(file), - undefined, - (event, filename) => { - if (isNotEmptyString(filename) && event === 'change') { - try { - logger.debug( - `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload`, - ); - this.deleteIdTagsCache(file); - this.deleteIdTagsCacheIndexes(file); - } catch (error) { - handleFileException( - file, - FileType.Authorization, - error as NodeJS.ErrnoException, - this.logPrefix(file), - { - throwError: false, - }, - ); - } - } - }, - ), + // FIXME: Disabled until the spurious configuration file change detection is identified + // idTagsFileWatcher: watchJsonFile( + // file, + // FileType.Authorization, + // this.logPrefix(file), + // undefined, + // (event, filename) => { + // if (isNotEmptyString(filename) && event === 'change') { + // try { + // logger.debug( + // `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload`, + // ); + // this.deleteIdTagsCache(file); + // this.deleteIdTagsCacheIndexes(file); + // } catch (error) { + // handleFileException( + // file, + // FileType.Authorization, + // error as NodeJS.ErrnoException, + // this.logPrefix(file), + // { + // throwError: false, + // }, + // ); + // } + // } + // }, + // ), }); } diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 1f370480..ebf99c55 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -529,9 +529,10 @@ export class Configuration { Configuration.configurationData = JSON.parse( readFileSync(Configuration.configurationFile, 'utf8'), ) as ConfigurationData; - if (!Configuration.configurationFileWatcher) { - Configuration.configurationFileWatcher = Configuration.getConfigurationFileWatcher(); - } + // FIXME: Disabled until the spurious configuration file change detection is identified + // if (!Configuration.configurationFileWatcher) { + // Configuration.configurationFileWatcher = Configuration.getConfigurationFileWatcher(); + // } } catch (error) { Configuration.handleFileException( Configuration.configurationFile, -- 2.34.1