// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
-import { ChargingStationWorkerData, WorkerMessage, WorkerMessageEvents } from '../types/Worker';
+import { ChargingStationWorkerData, ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker';
import Configuration from '../utils/Configuration';
import { Storage } from '../performance/storage/Storage';
poolOptions: {
workerChoiceStrategy: Configuration.getWorkerPoolStrategy()
},
- messageHandler: async (msg: WorkerMessage) => {
- if (msg.id === WorkerMessageEvents.PERFORMANCE_STATISTICS) {
+ messageHandler: async (msg: ChargingStationWorkerMessage) => {
+ if (msg.id === ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS) {
await Bootstrap.storage.storePerformanceStatistics(msg.data);
}
}
// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
-import { ChargingStationWorkerData, WorkerMessage, WorkerMessageEvents } from '../types/Worker';
+import { ChargingStationWorkerData, ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker';
import { parentPort, workerData } from 'worker_threads';
import ChargingStation from './ChargingStation';
* Listen messages send by the main thread
*/
function addMessageListener(): void {
- parentPort?.on('message', (message: WorkerMessage) => {
- if (message.id === WorkerMessageEvents.START_WORKER_ELEMENT) {
+ parentPort?.on('message', (message: ChargingStationWorkerMessage) => {
+ if (message.id === ChargingStationWorkerMessageEvents.START_WORKER_ELEMENT) {
startChargingStation(message.data);
}
});
import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks';
import Statistics, { StatisticsData } from '../types/Statistics';
+import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker';
import Configuration from '../utils/Configuration';
import { MessageType } from '../types/ocpp/MessageType';
import { URL } from 'url';
import Utils from '../utils/Utils';
-import { WorkerMessageEvents } from '../types/Worker';
import logger from '../utils/Logger';
import { parentPort } from 'worker_threads';
this.statistics.statisticsData[entryName].ninetyFiveThPercentileTimeMeasurement = this.percentile(this.statistics.statisticsData[entryName].timeMeasurementSeries, 95);
this.statistics.statisticsData[entryName].stdDevTimeMeasurement = this.stdDeviation(this.statistics.statisticsData[entryName].timeMeasurementSeries);
if (Configuration.getPerformanceStorage().enabled) {
- parentPort.postMessage({ id: WorkerMessageEvents.PERFORMANCE_STATISTICS, data: this.statistics });
+ parentPort.postMessage({ id: ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS, data: this.statistics });
}
}
--- /dev/null
+import { WorkerData, WorkerMessage, WorkerMessageEvents } from './Worker';
+
+export interface ChargingStationWorkerData extends WorkerData {
+ index: number;
+ templateFile: string;
+}
+
+enum InternalChargingStationWorkerMessageEvents {
+ PERFORMANCE_STATISTICS = 'performanceStatistics'
+}
+
+export type ChargingStationWorkerMessageEvents = WorkerMessageEvents | InternalChargingStationWorkerMessageEvents;
+
+export const ChargingStationWorkerMessageEvents = {
+ ...WorkerMessageEvents,
+ ...InternalChargingStationWorkerMessageEvents
+};
+
+
+export interface ChargingStationWorkerMessage extends Omit<WorkerMessage, 'id'> {
+ id: ChargingStationWorkerMessageEvents;
+}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface WorkerData {}
-export interface ChargingStationWorkerData extends WorkerData {
- index: number;
- templateFile: string;
-}
-
export interface WorkerSetElement {
worker: Worker;
numberOfWorkerElements: number;
export enum WorkerMessageEvents {
START_WORKER_ELEMENT = 'startWorkerElement',
- STOP_WORKER_ELEMENT = 'stopWorkerElement',
- PERFORMANCE_STATISTICS = 'performanceStatistics'
+ STOP_WORKER_ELEMENT = 'stopWorkerElement'
}