X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerConstants.ts;h=ded5c89142f8e2aa9f485ed9df6ea476a7832100;hb=53d4c02ab3f09e4e622ac6b7558f26ec90816bdb;hp=99e29fcb6bd57c1bc0806b9778a7502933707c86;hpb=60d1f5b09771029bd3459a620e883c58dab0d4f5;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerConstants.ts b/src/worker/WorkerConstants.ts index 99e29fcb..ded5c891 100644 --- a/src/worker/WorkerConstants.ts +++ b/src/worker/WorkerConstants.ts @@ -1,18 +1,31 @@ -import { availableParallelism } from 'poolifier'; +import { availableParallelism } from 'poolifier' -export class WorkerConstants { - public static readonly EMPTY_FUNCTION = Object.freeze(() => { - /* This is intentional */ - }); +import type { WorkerOptions } from './WorkerTypes.js' +import { defaultErrorHandler, defaultExitHandler } from './WorkerUtils.js' - 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 = availableParallelism() / 2; - public static readonly DEFAULT_POOL_MAX_SIZE = availableParallelism(); - public static readonly DEFAULT_ELEMENTS_PER_WORKER = 1; +export const EMPTY_FUNCTION = Object.freeze(() => { + /* This is intentional */ +}) - private constructor() { - // This is intentional +export const workerSetVersion = '1.0.1' + +export const DEFAULT_ELEMENT_ADD_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, + elementAddDelay: DEFAULT_ELEMENT_ADD_DELAY, + poolMinSize: DEFAULT_POOL_MIN_SIZE, + poolMaxSize: DEFAULT_POOL_MAX_SIZE, + elementsPerWorker: DEFAULT_ELEMENTS_PER_WORKER, + poolOptions: { + startWorkers: false, + enableEvents: true, + restartWorkerOnError: true, + errorHandler: defaultErrorHandler, + exitHandler: defaultExitHandler } -} +})