X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerAbstract.ts;h=0fccdb812d7ed4c2a40b28596a3cfc883ed606e3;hb=78202038ffd2aca15aa97f45bc66ba42f40f2ec4;hp=12cc7c735f257ed624c8de35d5198865361edec7;hpb=4d7227e61934a6b082a4d89268c454f7ee3605e1;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 12cc7c73..0fccdb81 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -1,6 +1,7 @@ -import { WorkerData, WorkerOptions } from '../types/Worker'; +import fs from 'fs'; -import Constants from '../utils/Constants'; +import WorkerConstants from './WorkerConstants'; +import type { WorkerData, WorkerOptions } from '../types/Worker'; export default abstract class WorkerAbstract { protected readonly workerScript: string; @@ -11,18 +12,29 @@ export default abstract class WorkerAbstract { /** * `WorkerAbstract` constructor. * - * @param workerScript - * @param workerOptions + * @param workerScript - + * @param workerOptions - */ - constructor(workerScript: string, workerOptions: WorkerOptions = { - workerStartDelay: Constants.WORKER_START_DELAY, - elementStartDelay: Constants.ELEMENT_START_DELAY, - poolMinSize: Constants.DEFAULT_WORKER_POOL_MIN_SIZE, - poolMaxSize: Constants.DEFAULT_WORKER_POOL_MAX_SIZE, - elementsPerWorker: Constants.DEFAULT_CHARGING_STATIONS_PER_WORKER, - poolOptions: {}, - messageHandler: () => { /* This is intentional */ } - }) { + constructor( + workerScript: string, + workerOptions: WorkerOptions = { + workerStartDelay: WorkerConstants.DEFAULT_WORKER_START_DELAY, + elementStartDelay: WorkerConstants.DEFAULT_ELEMENT_START_DELAY, + poolMinSize: WorkerConstants.DEFAULT_POOL_MIN_SIZE, + poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE, + elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER, + poolOptions: {}, + messageHandler: () => { + /* This is intentional */ + }, + } + ) { + if (!workerScript) { + throw new Error('Worker script is not defined'); + } + if (!fs.existsSync(workerScript)) { + throw new Error('Worker script file does not exist'); + } this.workerScript = workerScript; this.workerOptions = workerOptions; }