fix: fix setInterval deferencing
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 20 Mar 2023 22:40:56 +0000 (23:40 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 20 Mar 2023 22:40:56 +0000 (23:40 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/performance/PerformanceStatistics.ts

index c24383e90c84fe122d8aa2165d17820bd71d4205..718f5eff7bfb0b21acd808e53e9cb080729e84d1 100644 (file)
@@ -1940,6 +1940,7 @@ export class ChargingStation {
   private stopWebSocketPing(): void {
     if (this.webSocketPingSetInterval) {
       clearInterval(this.webSocketPingSetInterval);
+      delete this.webSocketPingSetInterval;
     }
   }
 
@@ -1997,6 +1998,7 @@ export class ChargingStation {
   private stopHeartbeat(): void {
     if (this.heartbeatSetInterval) {
       clearInterval(this.heartbeatSetInterval);
+      delete this.heartbeatSetInterval;
     }
   }
 
index 69829ff186e71fd1aca40e465b1c4b654084c8fc..8cf0e1ef5d9f9541913f9c72cbf6a7310dee19cf 100644 (file)
@@ -127,6 +127,7 @@ export class PerformanceStatistics {
   public stop(): void {
     if (this.displayInterval) {
       clearInterval(this.displayInterval);
+      delete this.displayInterval;
     }
     performance.clearMarks();
     performance.clearMeasures();
@@ -158,7 +159,7 @@ export class PerformanceStatistics {
   }
 
   private startLogStatisticsInterval(): void {
-    if (Configuration.getLogStatisticsInterval() > 0) {
+    if (Configuration.getLogStatisticsInterval() > 0 && !this.displayInterval) {
       this.displayInterval = setInterval(() => {
         this.logStatistics();
       }, Configuration.getLogStatisticsInterval() * 1000);
@@ -167,6 +168,12 @@ export class PerformanceStatistics {
           Configuration.getLogStatisticsInterval()
         )}`
       );
+    } else if (this.displayInterval) {
+      logger.info(
+        `${this.logPrefix()} already logged every ${Utils.formatDurationSeconds(
+          Configuration.getLogStatisticsInterval()
+        )}`
+      );
     } else {
       logger.info(
         `${this.logPrefix()} log interval is set to ${Configuration.getLogStatisticsInterval()?.toString()}. Not logging statistics`