throw new TypeError('Invalid tasks queue options: must be a plain object')
}
if (
- tasksQueueOptions?.concurrency != null &&
+ tasksQueueOptions.concurrency != null &&
!Number.isSafeInteger(tasksQueueOptions.concurrency)
) {
throw new TypeError(
)
}
if (
- tasksQueueOptions?.concurrency != null &&
+ tasksQueueOptions.concurrency != null &&
tasksQueueOptions.concurrency <= 0
) {
throw new RangeError(
`Invalid worker node tasks concurrency: ${tasksQueueOptions.concurrency} is a negative integer or zero`
)
}
- if (tasksQueueOptions?.queueMaxSize != null) {
+ if (tasksQueueOptions.queueMaxSize != null) {
throw new Error(
'Invalid tasks queue options: queueMaxSize is deprecated, please use size instead'
)
}
if (
- tasksQueueOptions?.size != null &&
+ tasksQueueOptions.size != null &&
!Number.isSafeInteger(tasksQueueOptions.size)
) {
throw new TypeError(
'Invalid worker node tasks queue size: must be an integer'
)
}
- if (tasksQueueOptions?.size != null && tasksQueueOptions.size <= 0) {
+ if (tasksQueueOptions.size != null && tasksQueueOptions.size <= 0) {
throw new RangeError(
`Invalid worker node tasks queue size: ${tasksQueueOptions.size} is a negative integer or zero`
)
}
const timestamp = performance.now()
const workerNodeKey = this.chooseWorkerNode()
- const workerInfo = this.getWorkerInfo(workerNodeKey) as WorkerInfo
+ const workerInfo = this.getWorkerInfo(workerNodeKey)
const task: Task<Data> = {
name: name ?? DEFAULT_TASK_NAME,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
worker.on('error', this.opts.errorHandler ?? EMPTY_FUNCTION)
worker.on('error', (error) => {
const workerNodeKey = this.getWorkerNodeKeyByWorker(worker)
- const workerInfo = this.getWorkerInfo(workerNodeKey) as WorkerInfo
+ const workerInfo = this.getWorkerInfo(workerNodeKey)
workerInfo.ready = false
this.workerNodes[workerNodeKey].closeChannel()
this.emitter?.emit(PoolEvents.error, error)
})
}
})
- const workerInfo = this.getWorkerInfo(workerNodeKey) as WorkerInfo
+ const workerInfo = this.getWorkerInfo(workerNodeKey)
this.sendToWorker(workerNodeKey, {
checkActive: true,
workerId: workerInfo.id as number
elu: this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
.elu.aggregate
},
- workerId: (this.getWorkerInfo(workerNodeKey) as WorkerInfo).id as number
+ workerId: this.getWorkerInfo(workerNodeKey).id as number
})
}
this.handleTaskExecutionResponse(message)
} else if (message.taskFunctions != null) {
// Task functions message received from worker
- (
- this.getWorkerInfo(
- this.getWorkerNodeKeyByWorkerId(message.workerId)
- ) as WorkerInfo
+ this.getWorkerInfo(
+ this.getWorkerNodeKeyByWorkerId(message.workerId)
).taskFunctions = message.taskFunctions
}
}
}
const workerInfo = this.getWorkerInfo(
this.getWorkerNodeKeyByWorkerId(message.workerId)
- ) as WorkerInfo
+ )
workerInfo.ready = message.ready as boolean
workerInfo.taskFunctions = message.taskFunctions
if (this.emitter != null && this.ready) {
* @param workerNodeKey - The worker node key.
* @returns The worker information.
*/
- protected getWorkerInfo (workerNodeKey: number): WorkerInfo | undefined {
- return this.workerNodes[workerNodeKey]?.info
+ protected getWorkerInfo (workerNodeKey: number): WorkerInfo {
+ return this.workerNodes[workerNodeKey].info
}
/**
*/
protected getWorkerNodeTaskRunTime (workerNodeKey: number): number {
return this.taskStatisticsRequirements.runTime.median
- ? this.pool.workerNodes[workerNodeKey]?.usage?.runTime?.median ?? 0
- : this.pool.workerNodes[workerNodeKey]?.usage?.runTime?.average ?? 0
+ ? this.pool.workerNodes[workerNodeKey].usage.runTime.median ?? 0
+ : this.pool.workerNodes[workerNodeKey].usage.runTime.average ?? 0
}
/**
*/
protected getWorkerNodeTaskWaitTime (workerNodeKey: number): number {
return this.taskStatisticsRequirements.waitTime.median
- ? this.pool.workerNodes[workerNodeKey]?.usage?.waitTime?.median ?? 0
- : this.pool.workerNodes[workerNodeKey]?.usage?.waitTime?.average ?? 0
+ ? this.pool.workerNodes[workerNodeKey].usage.waitTime.median ?? 0
+ : this.pool.workerNodes[workerNodeKey].usage.waitTime.average ?? 0
}
/**
*/
protected getWorkerNodeTaskElu (workerNodeKey: number): number {
return this.taskStatisticsRequirements.elu.median
- ? this.pool.workerNodes[workerNodeKey]?.usage?.elu?.active?.median ?? 0
- : this.pool.workerNodes[workerNodeKey]?.usage?.elu?.active?.average ?? 0
+ ? this.pool.workerNodes[workerNodeKey].usage.elu.active.median ?? 0
+ : this.pool.workerNodes[workerNodeKey].usage.elu.active.average ?? 0
}
/**
private leastBusyNextWorkerNodeKey (): number | undefined {
return this.pool.workerNodes.reduce(
(minWorkerNodeKey, workerNode, workerNodeKey, workerNodes) => {
- return (workerNode.usage.runTime?.aggregate ?? 0) +
- (workerNode.usage.waitTime?.aggregate ?? 0) <
- (workerNodes[minWorkerNodeKey].usage.runTime?.aggregate ?? 0) +
- (workerNodes[minWorkerNodeKey].usage.waitTime?.aggregate ?? 0)
+ return (workerNode.usage.runTime.aggregate ?? 0) +
+ (workerNode.usage.waitTime.aggregate ?? 0) <
+ (workerNodes[minWorkerNodeKey].usage.runTime.aggregate ?? 0) +
+ (workerNodes[minWorkerNodeKey].usage.waitTime.aggregate ?? 0)
? workerNodeKey
: minWorkerNodeKey
},