X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerConstants.ts;h=8c66df029213ca4876f213ca2dcb552a27317bbb;hb=bcbb76a6957d1c0bad4a51c040af58788b8b186f;hp=4e0bce1f86dca990f99be28649b0dafe50620488;hpb=628c30e510dd0f12be4432bd5eb0ff86790c4de0;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerConstants.ts b/src/worker/WorkerConstants.ts index 4e0bce1f..8c66df02 100644 --- a/src/worker/WorkerConstants.ts +++ b/src/worker/WorkerConstants.ts @@ -1,20 +1,29 @@ -import { availableParallelism } from 'poolifier'; +import { type ThreadPoolOptions, availableParallelism } from 'poolifier'; -export class WorkerConstants { - public static readonly EMPTY_FUNCTION = Object.freeze(() => { - /* This is intentional */ - }); +import type { WorkerOptions } from './WorkerTypes'; - 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 */ +}); - public static readonly version = '1.0.0'; +export const workerSetVersion = '1.0.1'; - private constructor() { - // This is intentional - } -} +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: {}, +}); + +export const DEFAULT_POOL_OPTIONS: ThreadPoolOptions = { + enableEvents: true, + restartWorkerOnError: true, +};