From: Jérôme Benoit Date: Sun, 12 Nov 2023 09:57:53 +0000 (+0100) Subject: refactor: make ATG wait busy loop test first X-Git-Tag: v1.2.24~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=60400e2350178b24e06fc98e6f52cdb7317e03a3;p=e-mobility-charging-stations-simulator.git refactor: make ATG wait busy loop test first Signed-off-by: Jérôme Benoit --- diff --git a/package.json b/package.json index 2f20c035..7d60ebbb 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "utf-8-validate": "^6.0.3" }, "devDependencies": { - "@commitlint/cli": "^18.4.0", + "@commitlint/cli": "^18.4.1", "@commitlint/config-conventional": "^18.4.0", "@mikro-orm/cli": "^5.9.3", "@release-it/bumper": "^6.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8e288ba1..3aa65c7e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -85,8 +85,8 @@ optionalDependencies: devDependencies: '@commitlint/cli': - specifier: ^18.4.0 - version: 18.4.0(typescript@5.2.2) + specifier: ^18.4.1 + version: 18.4.1(typescript@5.2.2) '@commitlint/config-conventional': specifier: ^18.4.0 version: 18.4.0 @@ -413,14 +413,14 @@ packages: engines: {node: '>=0.1.90'} dev: false - /@commitlint/cli@18.4.0(typescript@5.2.2): - resolution: {integrity: sha512-iz3KJtmsRRFm6OlyrORxRR6qcrznuoFDzcvMXTMpl6E/wj9Vr2crolDk6cG3bFpJCjWd9C7KidXerRha6hh1kQ==} + /@commitlint/cli@18.4.1(typescript@5.2.2): + resolution: {integrity: sha512-4+jljfd29Udw9RDDyigavLO9LvdbmB8O9xjDzVZ0R3lJuG7nCeyHgnKWIVpFaN590isZMV/cMeQK0gH7hRF40A==} engines: {node: '>=v18'} hasBin: true dependencies: '@commitlint/format': 18.4.0 '@commitlint/lint': 18.4.0 - '@commitlint/load': 18.4.0(typescript@5.2.2) + '@commitlint/load': 18.4.1(typescript@5.2.2) '@commitlint/read': 18.4.0 '@commitlint/types': 18.4.0 execa: 5.1.1 @@ -490,8 +490,8 @@ packages: '@commitlint/types': 18.4.0 dev: true - /@commitlint/load@18.4.0(typescript@5.2.2): - resolution: {integrity: sha512-7unGl1HGRNMgWrUPmj8OFkJyuNUMb6xA1i53/OAFKd9l+U3C4WTfoJe3t/TUz8vKZLCaDcWWR/b2cw5HveBBFg==} + /@commitlint/load@18.4.1(typescript@5.2.2): + resolution: {integrity: sha512-o/plBiPJQgbSq/4ipDpsq4HCmURjBAEjr1EO/p2falr3VhwV0WGXTvb8NlihgI8xtSyO6lHvtycrE535GMLQbA==} engines: {node: '>=v18'} dependencies: '@commitlint/config-validator': 18.4.0 diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index ebfd8c19..3d1e8b1c 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -320,41 +320,47 @@ export class AutomaticTransactionGenerator extends AsyncResource { } private async waitChargingStationServiceInitialization(connectorId: number): Promise { - if (!this.chargingStation?.ocppRequestService) { - logger.info( - `${this.logPrefix( - connectorId, - )} transaction loop waiting for charging station service to be initialized`, - ); - do { - await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME); - } while (!this.chargingStation?.ocppRequestService); + let logged = false; + while (!this.chargingStation?.ocppRequestService) { + if (!logged) { + logger.info( + `${this.logPrefix( + connectorId, + )} transaction loop waiting for charging station service to be initialized`, + ); + logged = true; + } + await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME); } } private async waitChargingStationAvailable(connectorId: number): Promise { - if (!this.chargingStation.isChargingStationAvailable()) { - logger.info( - `${this.logPrefix( - connectorId, - )} transaction loop waiting for charging station to be available`, - ); - do { - await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME); - } while (!this.chargingStation.isChargingStationAvailable()); + let logged = false; + while (!this.chargingStation.isChargingStationAvailable()) { + if (!logged) { + logger.info( + `${this.logPrefix( + connectorId, + )} transaction loop waiting for charging station to be available`, + ); + logged = true; + } + await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME); } } private async waitConnectorAvailable(connectorId: number): Promise { - if (!this.chargingStation.isConnectorAvailable(connectorId)) { - logger.info( - `${this.logPrefix( - connectorId, - )} transaction loop waiting for connector ${connectorId} to be available`, - ); - do { - await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME); - } while (!this.chargingStation.isConnectorAvailable(connectorId)); + let logged = false; + while (!this.chargingStation.isConnectorAvailable(connectorId)) { + if (!logged) { + logger.info( + `${this.logPrefix( + connectorId, + )} transaction loop waiting for connector ${connectorId} to be available`, + ); + logged = true; + } + await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME); } }