X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerConstants.ts;h=bbfcdac4b10a37b55adf26ee21d5385517b97ca9;hb=0a0da58d95d81782d92cd9a03c80ea6d3945aef6;hp=8e34a165c7fcb0eecb60856e86d487f1483fbe90;hpb=268a74bb051fcbbad532fd833f0d8fd2b33b6c64;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerConstants.ts b/src/worker/WorkerConstants.ts index 8e34a165..bbfcdac4 100644 --- a/src/worker/WorkerConstants.ts +++ b/src/worker/WorkerConstants.ts @@ -1,12 +1,30 @@ -export class WorkerConstants { - 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; - - private constructor() { - // This is intentional - } -} +import { type ThreadPoolOptions, availableParallelism } from 'poolifier'; + +import type { WorkerOptions } from './WorkerTypes'; + +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 POOL_MAX_INACTIVE_TIME = 60000; +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: {}, +}); + +export const DEFAULT_POOL_OPTIONS: ThreadPoolOptions = { + enableEvents: true, + restartWorkerOnError: true, +};