From: Jérôme Benoit Date: Wed, 5 Jun 2024 19:11:29 +0000 (+0200) Subject: refactor: cleanup connection retries logic X-Git-Tag: v1.3.4~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aa5f2ea2958ef34e8d34e20edbe8486b8911d82b;p=e-mobility-charging-stations-simulator.git refactor: cleanup connection retries logic Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 13fbee42..e8d6387f 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -181,7 +181,6 @@ export class ChargingStation extends EventEmitter { private ocppIncomingRequestService!: OCPPIncomingRequestService private readonly messageBuffer: Set private configuredSupervisionUrl!: URL - private wsConnectionRetried: boolean private wsConnectionRetryCount: number private templateFileWatcher?: FSWatcher private templateFileHash!: string @@ -196,7 +195,6 @@ export class ChargingStation extends EventEmitter { this.starting = false this.stopping = false this.wsConnection = null - this.wsConnectionRetried = false this.wsConnectionRetryCount = 0 this.index = index this.templateFile = templateFile @@ -225,16 +223,16 @@ export class ChargingStation extends EventEmitter { }) this.on(ChargingStationEvents.accepted, () => { this.startMessageSequence( - this.wsConnectionRetried + this.wsConnectionRetryCount > 0 ? true : this.getAutomaticTransactionGeneratorConfiguration()?.stopAbsoluteDuration ).catch((error: unknown) => { logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error) }) - this.wsConnectionRetried = false + this.wsConnectionRetryCount = 0 }) this.on(ChargingStationEvents.rejected, () => { - this.wsConnectionRetried = false + this.wsConnectionRetryCount = 0 }) this.on(ChargingStationEvents.connected, () => { if (this.wsPingSetInterval == null) { @@ -1875,7 +1873,6 @@ export class ChargingStation extends EventEmitter { })` ) } - this.wsConnectionRetryCount = 0 this.emit(ChargingStationEvents.updated) } else { logger.warn( @@ -2421,7 +2418,6 @@ export class ChargingStation extends EventEmitter { this.wsConnectionRetryCount < this.stationInfo!.autoReconnectMaxRetries! || this.stationInfo?.autoReconnectMaxRetries === -1 ) { - this.wsConnectionRetried = true ++this.wsConnectionRetryCount const reconnectDelay = this.stationInfo?.reconnectExponentialDelay === true