import type { URL } from 'node:url';
import { parentPort } from 'node:worker_threads';
+import { secondsToMilliseconds } from 'date-fns';
+
import {
+ ConfigurationSection,
type IncomingRequestCommand,
+ type LogConfiguration,
MessageType,
type RequestCommand,
type Statistics,
+ type StorageConfiguration,
type TimestampedData,
} from '../types';
import {
public start(): void {
this.startLogStatisticsInterval();
- if (Configuration.getPerformanceStorage().enabled) {
+ const performanceStorageConfiguration =
+ Configuration.getConfigurationSection<StorageConfiguration>(
+ ConfigurationSection.performanceStorage,
+ );
+ if (performanceStorageConfiguration.enabled) {
logger.info(
- `${this.logPrefix()} storage enabled: type ${
- Configuration.getPerformanceStorage().type
- }, uri: ${Configuration.getPerformanceStorage().uri}`,
+ `${this.logPrefix()} storage enabled: type ${performanceStorageConfiguration.type}, uri: ${
+ performanceStorageConfiguration.uri
+ }`,
);
}
}
}
private startLogStatisticsInterval(): void {
- const logStatisticsInterval = Configuration.getLog().enabled
- ? Configuration.getLog().statisticsInterval!
+ const logConfiguration = Configuration.getConfigurationSection<LogConfiguration>(
+ ConfigurationSection.log,
+ );
+ const logStatisticsInterval = logConfiguration.enabled
+ ? logConfiguration.statisticsInterval!
: 0;
if (logStatisticsInterval > 0 && !this.displayInterval) {
this.displayInterval = setInterval(() => {
this.logStatistics();
- }, logStatisticsInterval * 1000);
+ }, secondsToMilliseconds(logStatisticsInterval));
logger.info(
`${this.logPrefix()} logged every ${formatDurationSeconds(logStatisticsInterval)}`,
);
logger.info(
`${this.logPrefix()} already logged every ${formatDurationSeconds(logStatisticsInterval)}`,
);
- } else if (Configuration.getLog().enabled) {
+ } else if (logConfiguration.enabled) {
logger.info(
- `${this.logPrefix()} log interval is set to ${logStatisticsInterval?.toString()}. Not logging statistics`,
+ `${this.logPrefix()} log interval is set to ${logStatisticsInterval}. Not logging statistics`,
);
}
}
this.statistics.statisticsData.get(entryName)!.measurementTimeSeries as TimestampedData[],
),
);
- if (Configuration.getPerformanceStorage().enabled) {
+ if (
+ Configuration.getConfigurationSection<StorageConfiguration>(
+ ConfigurationSection.performanceStorage,
+ ).enabled
+ ) {
parentPort?.postMessage(buildPerformanceStatisticsMessage(this.statistics));
}
}