refactor: make ATG wait busy loop test first
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 12 Nov 2023 09:57:53 +0000 (10:57 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 12 Nov 2023 09:57:53 +0000 (10:57 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
package.json
pnpm-lock.yaml
src/charging-station/AutomaticTransactionGenerator.ts

index 2f20c03540e1a856b41b22e31081ae24e2268629..7d60ebbbe8e7d0292d5e96cafaaece58de6ae8ae 100644 (file)
     "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",
index 8e288ba1d1c1d1135624bb64f01db12f3408a78f..3aa65c7e7079fa5380672d1e55ce5be3db5791fb 100644 (file)
@@ -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
index ebfd8c196fd026b0ca673bba3cb5a38bff8a3e9d..3d1e8b1ccf2319dd694831d3792b337e60b7333d 100644 (file)
@@ -320,41 +320,47 @@ export class AutomaticTransactionGenerator extends AsyncResource {
   }
 
   private async waitChargingStationServiceInitialization(connectorId: number): Promise<void> {
-    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<void> {
-    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<void> {
-    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);
     }
   }