X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerAbstract.ts;h=27f947d1a0f04ec987b798c61948e1bed8572061;hb=e909d2a71e82122e970db9d6f262bd1415a3bb20;hp=c3e0ed88e9ae6fa4581b6e99b65bffa20931a546;hpb=e7aeea18e189dd087c8f951cf77a253e2818ae90;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index c3e0ed88..27f947d1 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 type { WorkerData, WorkerOptions } from '../types/Worker'; +import WorkerConstants from './WorkerConstants'; export default abstract class WorkerAbstract { protected readonly workerScript: string; @@ -17,17 +18,23 @@ export default abstract class WorkerAbstract { 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, + 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; }