refactor: refine OCPP stack log message
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerConstants.ts
index 72d436d439f444416524d4bc5245b26fb19ed01a..c7f8065ae1dc603842e78e6eae6a8c0fe7133e17 100644 (file)
@@ -1,16 +1,27 @@
-export class WorkerConstants {
-  public static readonly EMPTY_FUNCTION = Object.freeze(() => {
-    /* This is intentional */
-  });
+import { availableParallelism } from 'poolifier';
 
-  static readonly DEFAULT_ELEMENT_START_DELAY = 0;
-  static readonly DEFAULT_WORKER_START_DELAY = 500;
-  static readonly POOL_MAX_INACTIVE_TIME = 60000;
-  static readonly DEFAULT_POOL_MIN_SIZE = 4;
-  static readonly DEFAULT_POOL_MAX_SIZE = 16;
-  static readonly DEFAULT_ELEMENTS_PER_WORKER = 1;
+import type { WorkerOptions } from './WorkerTypes';
 
-  private constructor() {
-    // This is intentional
-  }
-}
+export const EMPTY_FUNCTION = Object.freeze(() => {
+  /* This is intentional */
+});
+
+export const workerSetVersion = '1.0.1';
+
+export const DEFAULT_ELEMENT_START_DELAY = 0;
+export const DEFAULT_WORKER_START_DELAY = 500;
+export const DEFAULT_POOL_MIN_SIZE = Math.floor(availableParallelism() / 2);
+export const DEFAULT_POOL_MAX_SIZE = Math.round(availableParallelism() * 1.5);
+export const DEFAULT_ELEMENTS_PER_WORKER = 1;
+
+export const DEFAULT_WORKER_OPTIONS: WorkerOptions = Object.freeze({
+  workerStartDelay: DEFAULT_WORKER_START_DELAY,
+  elementStartDelay: DEFAULT_ELEMENT_START_DELAY,
+  poolMinSize: DEFAULT_POOL_MIN_SIZE,
+  poolMaxSize: DEFAULT_POOL_MAX_SIZE,
+  elementsPerWorker: DEFAULT_ELEMENTS_PER_WORKER,
+  poolOptions: {
+    enableEvents: true,
+    restartWorkerOnError: true,
+  },
+});