* The start timestamp of the pool.
*/
private readonly startTimestamp
- /**
- * The task function names.
- */
- private taskFunctions!: string[]
/**
* Constructs a new poolifier pool.
/** @inheritDoc */
public listTaskFunctions (): string[] {
- if (this.taskFunctions != null) {
- return this.taskFunctions
+ if (
+ Array.isArray(this.getWorkerInfo(0).taskFunctions) &&
+ (this.getWorkerInfo(0).taskFunctions as string[]).length > 0
+ ) {
+ return this.getWorkerInfo(0).taskFunctions as string[]
} else {
return []
}
) {
reject(new TypeError('name argument must not be an empty string'))
}
+ if (transferList != null && !Array.isArray(transferList)) {
+ reject(new TypeError('transferList argument must be an array'))
+ }
+ const timestamp = performance.now()
+ const workerNodeKey = this.chooseWorkerNode()
if (
name != null &&
- this.taskFunctions != null &&
- !this.taskFunctions.includes(name)
+ Array.isArray(this.getWorkerInfo(workerNodeKey).taskFunctions) &&
+ !(this.getWorkerInfo(workerNodeKey).taskFunctions as string[]).includes(
+ name
+ )
) {
reject(
new Error(`Task function '${name}' is not registered in the pool`)
)
}
- if (transferList != null && !Array.isArray(transferList)) {
- reject(new TypeError('transferList argument must be an array'))
- }
- const timestamp = performance.now()
- const workerNodeKey = this.chooseWorkerNode()
const task: Task<Data> = {
name: name ?? DEFAULT_TASK_NAME,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const workerUsage = this.workerNodes[workerNodeKey].usage
++workerUsage.tasks.executing
this.updateWaitTimeWorkerUsage(workerUsage, task)
- const taskWorkerUsage = this.workerNodes[workerNodeKey].getTaskWorkerUsage(
- task.name as string
- ) as WorkerUsage
- ++taskWorkerUsage.tasks.executing
- this.updateWaitTimeWorkerUsage(taskWorkerUsage, task)
+ if (this.canUpdateTaskWorkerUsage(workerNodeKey)) {
+ const taskWorkerUsage = this.workerNodes[
+ workerNodeKey
+ ].getTaskWorkerUsage(task.name as string) as WorkerUsage
+ ++taskWorkerUsage.tasks.executing
+ this.updateWaitTimeWorkerUsage(taskWorkerUsage, task)
+ }
}
/**
this.updateTaskStatisticsWorkerUsage(workerUsage, message)
this.updateRunTimeWorkerUsage(workerUsage, message)
this.updateEluWorkerUsage(workerUsage, message)
- const taskWorkerUsage = this.workerNodes[workerNodeKey].getTaskWorkerUsage(
- message.taskPerformance?.name ?? DEFAULT_TASK_NAME
- ) as WorkerUsage
- this.updateTaskStatisticsWorkerUsage(taskWorkerUsage, message)
- this.updateRunTimeWorkerUsage(taskWorkerUsage, message)
- this.updateEluWorkerUsage(taskWorkerUsage, message)
+ if (this.canUpdateTaskWorkerUsage(workerNodeKey)) {
+ const taskWorkerUsage = this.workerNodes[
+ workerNodeKey
+ ].getTaskWorkerUsage(
+ message.taskPerformance?.name ?? DEFAULT_TASK_NAME
+ ) as WorkerUsage
+ this.updateTaskStatisticsWorkerUsage(taskWorkerUsage, message)
+ this.updateRunTimeWorkerUsage(taskWorkerUsage, message)
+ this.updateEluWorkerUsage(taskWorkerUsage, message)
+ }
+ }
+
+ private canUpdateTaskWorkerUsage (workerNodeKey: number): boolean {
+ return (
+ Array.isArray(this.getWorkerInfo(workerNodeKey).taskFunctions) &&
+ (this.getWorkerInfo(workerNodeKey).taskFunctions as string[]).length > 1
+ )
}
private updateTaskStatisticsWorkerUsage (
this.handleTaskExecutionResponse(message)
} else if (message.taskFunctions != null) {
// Task functions message received from worker
- this.taskFunctions = message.taskFunctions
+ this.getWorkerInfo(
+ this.getWorkerNodeKeyByWorkerId(message.workerId)
+ ).taskFunctions = message.taskFunctions
}
}
}
import { CircularArray } from '../circular-array'
import { Queue } from '../queue'
import type { Task } from '../utility-types'
+import { DEFAULT_TASK_NAME } from '../utils'
import {
type IWorker,
type IWorkerNode,
public readonly worker: Worker
public readonly info: WorkerInfo
public usage: WorkerUsage
+ public taskFunctions!: string[]
private readonly tasksUsage: Map<string, WorkerUsage>
private readonly tasksQueue: Queue<Task<Data>>
/** @inheritdoc */
public getTaskWorkerUsage (name: string): WorkerUsage | undefined {
+ if (
+ name === DEFAULT_TASK_NAME &&
+ Array.isArray(this.taskFunctions) &&
+ this.taskFunctions.length > 1
+ ) {
+ name = this.taskFunctions[1]
+ }
if (!this.tasksUsage.has(name)) {
this.tasksUsage.set(name, this.initTaskWorkerUsage(name))
}