X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FAutomaticTransactionGenerator.ts;h=80c9a5176937a035dccc699fc39e6e6b2859a88d;hb=96a52d088b4927e7bc51ea9282f502c2a6b67707;hp=e32c3c98109f6f520142d1499411b35d12babfcc;hpb=e6159ce8b782e3464a9a0dc377897bc4a4718121;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index e32c3c98..80c9a517 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { AsyncResource } from 'async_hooks'; @@ -69,6 +69,9 @@ export default class AutomaticTransactionGenerator extends AsyncResource { } public start(): void { + if (this.checkChargingStation() === false) { + return; + } if (this.started === true) { logger.warn(`${this.logPrefix()} is already started`); return; @@ -87,6 +90,9 @@ export default class AutomaticTransactionGenerator extends AsyncResource { } public startConnector(connectorId: number): void { + if (this.checkChargingStation(connectorId) === false) { + return; + } if (this.connectorsStatus.has(connectorId) === false) { logger.error(`${this.logPrefix(connectorId)} starting on non existing connector`); throw new BaseError(`Connector ${connectorId} does not exist`); @@ -96,10 +102,12 @@ export default class AutomaticTransactionGenerator extends AsyncResource { this.internalStartConnector.bind(this) as ( this: AutomaticTransactionGenerator, ...args: any[] - ) => void, + ) => Promise, this, connectorId - ); + ).catch(() => { + /* This is intentional */ + }); } else if (this.connectorsStatus.get(connectorId)?.start === true) { logger.warn(`${this.logPrefix(connectorId)} is already started on connector`); } @@ -445,4 +453,12 @@ export default class AutomaticTransactionGenerator extends AsyncResource { this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++; } } + + private checkChargingStation(connectorId?: number): boolean { + if (this.chargingStation.started === false && this.chargingStation.starting === false) { + logger.warn(`${this.logPrefix(connectorId)} charging station is stopped, cannot proceed`); + return false; + } + return true; + } }