X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerConstants.ts;h=404840954ddd702c32207853695764fe5379404a;hb=17ba3be0bb5c0bcb7fff2cefa877af975c0d043a;hp=635bfe529a82c79deba2ac60f6486a6c1672396b;hpb=ceec2441596cccd7bc5249721cd9ac8487cb920f;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerConstants.ts b/src/worker/WorkerConstants.ts index 635bfe52..40484095 100644 --- a/src/worker/WorkerConstants.ts +++ b/src/worker/WorkerConstants.ts @@ -1,16 +1,30 @@ -export class WorkerConstants { - public static readonly EMPTY_FUNCTION = Object.freeze(() => { - /* This is intentional */ - }); +import { availableParallelism } from 'poolifier' - public static readonly DEFAULT_ELEMENT_START_DELAY = 0; - public static readonly DEFAULT_WORKER_START_DELAY = 500; - public static readonly POOL_MAX_INACTIVE_TIME = 60000; - public static readonly DEFAULT_POOL_MIN_SIZE = 4; - public static readonly DEFAULT_POOL_MAX_SIZE = 16; - public static readonly DEFAULT_ELEMENTS_PER_WORKER = 1; +import type { WorkerOptions } from './WorkerTypes.js' +import { defaultErrorHandler, defaultExitHandler } from './WorkerUtils.js' - 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, + errorHandler: defaultErrorHandler, + exitHandler: defaultExitHandler } -} +})