repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: switch to public static instead of setter in configuration
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
Bootstrap.ts
diff --git
a/src/charging-station/Bootstrap.ts
b/src/charging-station/Bootstrap.ts
index 4bfea3213d822244acc028d75049f8a711cfe647..66b2d5f835146782bdb9a703b5002c9ab540146c 100644
(file)
--- a/
src/charging-station/Bootstrap.ts
+++ b/
src/charging-station/Bootstrap.ts
@@
-8,7
+8,7
@@
import { isMainThread } from 'node:worker_threads';
import chalk from 'chalk';
import { availableParallelism } from 'poolifier';
import chalk from 'chalk';
import { availableParallelism } from 'poolifier';
-import { waitChargingStationEvents } from './
ChargingStationUtil
s';
+import { waitChargingStationEvents } from './
Helper
s';
import type { AbstractUIServer } from './ui-server/AbstractUIServer';
import { UIServerFactory } from './ui-server/UIServerFactory';
import { version } from '../../package.json' assert { type: 'json' };
import type { AbstractUIServer } from './ui-server/AbstractUIServer';
import { UIServerFactory } from './ui-server/UIServerFactory';
import { version } from '../../package.json' assert { type: 'json' };
@@
-45,8
+45,10
@@
import { type WorkerAbstract, WorkerFactory } from '../worker';
const moduleName = 'Bootstrap';
enum exitCodes {
const moduleName = 'Bootstrap';
enum exitCodes {
+ succeeded = 0,
missingChargingStationsConfiguration = 1,
noChargingStationTemplates = 2,
missingChargingStationsConfiguration = 1,
noChargingStationTemplates = 2,
+ gracefulShutdownError = 3,
}
export class Bootstrap extends EventEmitter {
}
export class Bootstrap extends EventEmitter {
@@
-97,7
+99,7
@@
export class Bootstrap extends EventEmitter {
performanceStorageConfiguration.uri!,
this.logPrefix(),
));
performanceStorageConfiguration.uri!,
this.logPrefix(),
));
- Configuration.
setConfigurationChangeCallback(async () => Bootstrap.getInstance().restart()
);
+ Configuration.
configurationChangeCallback = async () => Bootstrap.getInstance().restart(
);
}
public static getInstance(): Bootstrap {
}
public static getInstance(): Bootstrap {
@@
-109,7
+111,7
@@
export class Bootstrap extends EventEmitter {
public async start(): Promise<void> {
if (!isMainThread) {
public async start(): Promise<void> {
if (!isMainThread) {
- throw new Error('Cannot start charging stations simulator from worker thread');
+ throw new
Base
Error('Cannot start charging stations simulator from worker thread');
}
if (this.started === false) {
if (this.starting === false) {
}
if (this.started === false) {
if (this.starting === false) {
@@
-176,7
+178,7
@@
export class Bootstrap extends EventEmitter {
public async stop(): Promise<void> {
if (!isMainThread) {
public async stop(): Promise<void> {
if (!isMainThread) {
- throw new Error('Cannot stop charging stations simulator from worker thread');
+ throw new
Base
Error('Cannot stop charging stations simulator from worker thread');
}
if (this.started === true) {
if (this.stopping === false) {
}
if (this.started === true) {
if (this.stopping === false) {
@@
-185,7
+187,7
@@
export class Bootstrap extends EventEmitter {
this.uiServer.buildProtocolRequest(
generateUUID(),
ProcedureName.STOP_CHARGING_STATION,
this.uiServer.buildProtocolRequest(
generateUUID(),
ProcedureName.STOP_CHARGING_STATION,
- Constants.EMPTY_FR
EEZED
_OBJECT,
+ Constants.EMPTY_FR
OZEN
_OBJECT,
),
);
await Promise.race([
),
);
await Promise.race([
@@
-230,7
+232,7
@@
export class Bootstrap extends EventEmitter {
if (workerConfiguration?.elementsPerWorker === 'auto') {
elementsPerWorker =
this.numberOfChargingStations > availableParallelism()
if (workerConfiguration?.elementsPerWorker === 'auto') {
elementsPerWorker =
this.numberOfChargingStations > availableParallelism()
- ? Math.round(this.numberOfChargingStations /
availableParallelism(
))
+ ? Math.round(this.numberOfChargingStations /
(availableParallelism() * 1.5
))
: 1;
}
this.workerImplementation === null &&
: 1;
}
this.workerImplementation === null &&
@@
-292,7
+294,9
@@
export class Bootstrap extends EventEmitter {
break;
default:
throw new BaseError(
break;
default:
throw new BaseError(
- `Unknown event type: '${msg.event}' for data: ${JSON.stringify(msg.data, null, 2)}`,
+ `Unknown charging station worker event: '${
+ msg.event
+ }' received with data: ${JSON.stringify(msg.data, null, 2)}`,
);
}
} catch (error) {
);
}
} catch (error) {
@@
-387,11
+391,11
@@
export class Bootstrap extends EventEmitter {
console.info(`${chalk.green('Graceful shutdown')}`);
this.stop()
.then(() => {
console.info(`${chalk.green('Graceful shutdown')}`);
this.stop()
.then(() => {
- process.exit(
0
);
+ process.exit(
exitCodes.succeeded
);
})
.catch((error) => {
console.error(chalk.red('Error while shutdowning charging stations simulator: '), error);
})
.catch((error) => {
console.error(chalk.red('Error while shutdowning charging stations simulator: '), error);
- process.exit(
1
);
+ process.exit(
exitCodes.gracefulShutdownError
);
});
};
});
};