X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker-node.ts;h=7667dd16a6b99c2994eaeda37866662b43f8d178;hb=8cc4ea811611b8ad77c7b0379911afe497f2e7e4;hp=812d14448f6fc4c7b221a74a23958920627f94ac;hpb=e2b31e32498626103ef3c737bdffb285087b13e6;p=poolifier.git diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 812d1444..7667dd16 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -28,7 +28,7 @@ implements IWorkerNode { public messageChannel?: MessageChannel /** @inheritdoc */ public usage: WorkerUsage - private readonly tasksUsage: Map + private readonly taskFunctionsUsage: Map private readonly tasksQueue: Queue> private readonly tasksQueueBackPressureSize: number @@ -46,7 +46,7 @@ implements IWorkerNode { this.messageChannel = new MessageChannel() } this.usage = this.initWorkerUsage() - this.tasksUsage = new Map() + this.taskFunctionsUsage = new Map() this.tasksQueue = new Queue>() this.tasksQueueBackPressureSize = Math.pow(poolMaxSize, 2) } @@ -88,7 +88,7 @@ implements IWorkerNode { /** @inheritdoc */ public resetUsage (): void { this.usage = this.initWorkerUsage() - this.tasksUsage.clear() + this.taskFunctionsUsage.clear() } /** @inheritdoc */ @@ -103,23 +103,27 @@ implements IWorkerNode { } /** @inheritdoc */ - public getTaskWorkerUsage (name: string): WorkerUsage | undefined { + public getTaskFunctionWorkerUsage (name: string): WorkerUsage | undefined { if (!Array.isArray(this.info.taskFunctions)) { throw new Error( - `Cannot get task worker usage for task function name '${name}' when task function names list is not yet defined` + `Cannot get task function worker usage for task function name '${name}' when task function names list is not yet defined` ) } if ( - name === DEFAULT_TASK_NAME && Array.isArray(this.info.taskFunctions) && - this.info.taskFunctions.length > 1 + this.info.taskFunctions.length < 3 ) { + throw new Error( + `Cannot get task function worker usage for task function name '${name}' when task function names list has less than 3 elements` + ) + } + if (name === DEFAULT_TASK_NAME) { name = this.info.taskFunctions[1] } - if (!this.tasksUsage.has(name)) { - this.tasksUsage.set(name, this.initTaskWorkerUsage(name)) + if (!this.taskFunctionsUsage.has(name)) { + this.taskFunctionsUsage.set(name, this.initTaskFunctionWorkerUsage(name)) } - return this.tasksUsage.get(name) + return this.taskFunctionsUsage.get(name) } private initWorkerInfo (worker: Worker, workerType: WorkerType): WorkerInfo { @@ -167,7 +171,7 @@ implements IWorkerNode { } } - private initTaskWorkerUsage (name: string): WorkerUsage { + private initTaskFunctionWorkerUsage (name: string): WorkerUsage { const getTaskQueueSize = (): number => { let taskQueueSize = 0 for (const task of this.tasksQueue) {