+
+ private workerEventStarted = (data: ChargingStationData) => {
+ this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
+ ++this.numberOfStartedChargingStations;
+ logger.info(
+ `${this.logPrefix()} ${moduleName}.workerEventStarted: Charging station ${
+ data.stationInfo.chargingStationId
+ } (hashId: ${data.stationInfo.hashId}) started (${
+ this.numberOfStartedChargingStations
+ } started from ${this.numberOfChargingStations})`
+ );
+ };
+
+ private workerEventStopped = (data: ChargingStationData) => {
+ this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
+ --this.numberOfStartedChargingStations;
+ logger.info(
+ `${this.logPrefix()} ${moduleName}.workerEventStopped: Charging station ${
+ data.stationInfo.chargingStationId
+ } (hashId: ${data.stationInfo.hashId}) stopped (${
+ this.numberOfStartedChargingStations
+ } started from ${this.numberOfChargingStations})`
+ );
+ };
+
+ private workerEventUpdated = (data: ChargingStationData) => {
+ this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
+ };
+
+ private workerEventPerformanceStatistics = (data: Statistics) => {
+ this.storage.storePerformanceStatistics(data) as void;
+ };
+
+ private initializeCounters() {
+ if (this.initializedCounters === false) {
+ this.numberOfChargingStationTemplates = 0;
+ this.numberOfChargingStations = 0;
+ const stationTemplateUrls = Configuration.getStationTemplateUrls();
+ if (Utils.isNotEmptyArray(stationTemplateUrls)) {
+ this.numberOfChargingStationTemplates = stationTemplateUrls.length;
+ stationTemplateUrls.forEach((stationTemplateUrl) => {
+ this.numberOfChargingStations += stationTemplateUrl.numberOfStations ?? 0;
+ });
+ } else {
+ console.warn(
+ chalk.yellow("'stationTemplateUrls' not defined or empty in configuration, exiting")
+ );
+ process.exit(exitCodes.missingChargingStationsConfiguration);
+ }
+ if (this.numberOfChargingStations === 0) {
+ console.warn(
+ chalk.yellow('No charging station template enabled in configuration, exiting')
+ );
+ process.exit(exitCodes.noChargingStationTemplates);
+ }
+ this.numberOfStartedChargingStations = 0;
+ this.initializedCounters = true;
+ }
+ }
+
+ private logUncaughtException(): void {
+ process.on('uncaughtException', (error: Error) => {
+ console.error(chalk.red('Uncaught exception: '), error);
+ });
+ }
+
+ private logUnhandledRejection(): void {
+ process.on('unhandledRejection', (reason: unknown) => {
+ console.error(chalk.red('Unhandled rejection: '), reason);
+ });
+ }
+
+ private async startChargingStation(
+ index: number,
+ stationTemplateUrl: StationTemplateUrl
+ ): Promise<void> {
+ await this.workerImplementation?.addElement({
+ index,
+ templateFile: path.join(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
+ 'assets',
+ 'station-templates',
+ stationTemplateUrl.file
+ ),
+ });
+ }
+
+ private logPrefix = (): string => {
+ return Utils.logPrefix(' Bootstrap |');
+ };