type TasksQueueOptions,
type WorkerType
} from './pool'
-import type {
- IWorker,
- Task,
- TaskStatistics,
- WorkerNode,
- WorkerUsage
-} from './worker'
+import type { IWorker, Task, WorkerNode, WorkerUsage } from './worker'
import {
Measurements,
WorkerChoiceStrategies,
if (workerChoiceStrategyOptions != null) {
this.setWorkerChoiceStrategyOptions(workerChoiceStrategyOptions)
}
- for (const workerNode of this.workerNodes) {
+ for (const [workerNodeKey, workerNode] of this.workerNodes.entries()) {
this.setWorkerNodeTasksUsage(
workerNode,
- this.getWorkerUsage(workerNode.worker)
+ this.getWorkerUsage(workerNodeKey)
)
this.setWorkerStatistics(workerNode.worker)
}
* @returns The worker nodes length.
*/
private pushWorkerNode (worker: Worker): number {
- return this.workerNodes.push({
+ this.workerNodes.push({
worker,
- workerUsage: this.getWorkerUsage(worker),
+ workerUsage: this.getWorkerUsage(),
tasksQueue: new Queue<Task<Data>>()
})
+ const workerNodeKey = this.getWorkerNodeKey(worker)
+ this.setWorkerNodeTasksUsage(
+ this.workerNodes[workerNodeKey],
+ this.getWorkerUsage(workerNodeKey)
+ )
+ return this.workerNodes.length
}
// /**
})
}
- private getWorkerUsage (worker: Worker): WorkerUsage {
+ private getWorkerUsage (workerNodeKey?: number): WorkerUsage {
+ const getQueueSize = (workerNodeKey: number): number => {
+ return this.tasksQueueSize(workerNodeKey)
+ }
return {
- tasks: this.getTaskStatistics(worker),
+ tasks: {
+ executed: 0,
+ executing: 0,
+ get queued (): number {
+ return workerNodeKey == null ? 0 : getQueueSize(workerNodeKey)
+ },
+ failed: 0
+ },
runTime: {
aggregate: 0,
average: 0,
}
}
}
-
- private getTaskStatistics (worker: Worker): TaskStatistics {
- const queueSize =
- this.workerNodes[this.getWorkerNodeKey(worker)]?.tasksQueue?.size
- return {
- executed: 0,
- executing: 0,
- get queued (): number {
- return queueSize ?? 0
- },
- failed: 0
- }
- }
}
queuePool.opts.tasksQueueOptions.concurrency
)
expect(workerNode.workerUsage.tasks.executed).toBe(0)
- expect(workerNode.tasksQueue.size).toBeGreaterThan(0)
+ expect(workerNode.workerUsage.tasks.queued).toBeGreaterThan(0)
}
expect(queuePool.info.executingTasks).toBe(numberOfWorkers)
expect(queuePool.info.queuedTasks).toBe(
expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
maxMultiplier
)
- expect(workerNode.tasksQueue.size).toBe(0)
+ expect(workerNode.workerUsage.tasks.queued).toBe(0)
}
})
queuePool.opts.tasksQueueOptions.concurrency
)
expect(workerNode.workerUsage.tasks.executed).toBe(0)
- expect(workerNode.tasksQueue.size).toBeGreaterThan(0)
+ expect(workerNode.workerUsage.tasks.queued).toBeGreaterThan(0)
}
expect(queuePool.info.executingTasks).toBe(numberOfThreads)
expect(queuePool.info.queuedTasks).toBe(
expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
maxMultiplier
)
- expect(workerNode.tasksQueue.size).toBe(0)
+ expect(workerNode.workerUsage.tasks.queued).toBe(0)
}
})