From aa428a31b4c462d38925ce60a215507c4b406b38 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 10 Sep 2022 06:11:50 +0200 Subject: [PATCH] Move some status attributes at constructor begin MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 2 +- src/charging-station/Bootstrap.ts | 3 ++- src/charging-station/ChargingStation.ts | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 706a4b8d..a09ee7a1 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -35,11 +35,11 @@ export default class AutomaticTransactionGenerator { automaticTransactionGeneratorConfiguration: AutomaticTransactionGeneratorConfiguration, chargingStation: ChargingStation ) { + this.started = false; this.configuration = automaticTransactionGeneratorConfiguration; this.chargingStation = chargingStation; this.connectorsStatus = new Map(); this.stopConnectors(); - this.started = false; } public static getInstance( diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 37cd1e64..d0c40162 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -35,7 +35,7 @@ const noChargingStationTemplatesExitCode = 2; export class Bootstrap { private static instance: Bootstrap | null = null; - private workerImplementation: WorkerAbstract | null = null; + private workerImplementation: WorkerAbstract | null; private readonly uiServer!: AbstractUIServer; private readonly storage!: Storage; private numberOfChargingStationTemplates!: number; @@ -47,6 +47,7 @@ export class Bootstrap { private constructor() { this.started = false; + this.workerImplementation = null; this.workerScript = path.join( path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'), 'charging-station', diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index bbb5c6f2..0775bcb9 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -114,6 +114,9 @@ export default class ChargingStation { private readonly chargingStationWorkerBroadcastChannel: ChargingStationWorkerBroadcastChannel; constructor(index: number, templateFile: string) { + this.started = false; + this.wsConnectionRestarted = false; + this.autoReconnectRetryCount = 0; this.index = index; this.templateFile = templateFile; this.connectors = new Map(); @@ -122,9 +125,6 @@ export default class ChargingStation { this.sharedLRUCache = SharedLRUCache.getInstance(); this.authorizedTagsCache = AuthorizedTagsCache.getInstance(); this.chargingStationWorkerBroadcastChannel = new ChargingStationWorkerBroadcastChannel(this); - this.started = false; - this.wsConnectionRestarted = false; - this.autoReconnectRetryCount = 0; this.initialize(); } @@ -1361,16 +1361,15 @@ export default class ChargingStation { if (this.isRegistered()) { if (this.isInAcceptedState()) { await this.startMessageSequence(); - this.wsConnectionRestarted && this.flushMessageBuffer(); } } else { logger.error( `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})` ); } - this.started === false && (this.started = true); - this.autoReconnectRetryCount = 0; this.wsConnectionRestarted = false; + this.autoReconnectRetryCount = 0; + this.started = true; parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); } else { logger.warn( @@ -1398,7 +1397,7 @@ export default class ChargingStation { code )}' and reason '${reason}'` ); - await this.reconnect(code); + await this.reconnect(); break; } parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); @@ -1814,6 +1813,7 @@ export default class ChargingStation { if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true) { this.startAutomaticTransactionGenerator(); } + this.wsConnectionRestarted === true && this.flushMessageBuffer(); } private async stopMessageSequence( @@ -1966,7 +1966,7 @@ export default class ChargingStation { : false; } - private async reconnect(code: number): Promise { + private async reconnect(): Promise { // Stop WebSocket ping this.stopWebSocketPing(); // Stop heartbeat -- 2.34.1