0
),
queuedTasks: this.workerNodes.reduce(
- (accumulator, workerNode) => accumulator + workerNode.tasksQueue.size,
+ (accumulator, workerNode) =>
+ accumulator + workerNode.workerUsage.tasks.queued,
0
),
maxQueuedTasks: this.workerNodes.reduce(
(accumulator, workerNode) =>
- accumulator + workerNode.tasksQueue.maxSize,
+ accumulator + workerNode.workerUsage.tasks.maxQueued,
0
),
failedTasks: this.workerNodes.reduce(
return this.workerNodes[workerNodeKey].tasksQueue.size
}
+ private tasksMaxQueueSize (workerNodeKey: number): number {
+ return this.workerNodes[workerNodeKey].tasksQueue.maxSize
+ }
+
private flushTasksQueue (workerNodeKey: number): void {
if (this.tasksQueueSize(workerNodeKey) > 0) {
for (let i = 0; i < this.tasksQueueSize(workerNodeKey); i++) {
)
}
}
+ this.workerNodes[workerNodeKey].tasksQueue.clear()
}
private flushTasksQueues (): void {
const getTasksQueueSize = (workerNodeKey?: number): number => {
return workerNodeKey != null ? this.tasksQueueSize(workerNodeKey) : 0
}
+ const getTasksMaxQueueSize = (workerNodeKey?: number): number => {
+ return workerNodeKey != null ? this.tasksMaxQueueSize(workerNodeKey) : 0
+ }
return {
tasks: {
executed: 0,
get queued (): number {
return getTasksQueueSize(workerNodeKey)
},
+ get maxQueued (): number {
+ return getTasksMaxQueueSize(workerNodeKey)
+ },
failed: 0
},
runTime: {
* Number of queued tasks.
*/
readonly queued: number
+ /**
+ * Maximum number of queued tasks.
+ */
+ readonly maxQueued: number
/**
* Number of failed tasks.
*/
}
return this.items[this.offset]
}
+
+ /**
+ * Clear the queue.
+ */
+ public clear (): void {
+ this.items = []
+ this.offset = 0
+ this.size = 0
+ this.maxSize = 0
+ }
}
executed: 0,
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: 0,
executing: maxMultiplier,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: maxMultiplier,
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: 0,
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
)
expect(workerNode.workerUsage.tasks.executed).toBe(0)
expect(workerNode.workerUsage.tasks.queued).toBeGreaterThan(0)
+ expect(workerNode.workerUsage.tasks.maxQueued).toBeGreaterThan(0)
}
expect(queuePool.info.executingTasks).toBe(numberOfWorkers)
expect(queuePool.info.queuedTasks).toBe(
maxMultiplier
)
expect(workerNode.workerUsage.tasks.queued).toBe(0)
+ expect(workerNode.workerUsage.tasks.maxQueued).toBe(1)
}
})
executed: maxMultiplier,
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: maxMultiplier,
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: expect.any(Number),
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: maxMultiplier,
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
executed: maxMultiplier,
executing: 0,
queued: 0,
+ maxQueued: 0,
failed: 0
},
runTime: {
)
expect(workerNode.workerUsage.tasks.executed).toBe(0)
expect(workerNode.workerUsage.tasks.queued).toBeGreaterThan(0)
+ expect(workerNode.workerUsage.tasks.maxQueued).toBeGreaterThan(0)
}
expect(queuePool.info.executingTasks).toBe(numberOfThreads)
expect(queuePool.info.queuedTasks).toBe(
maxMultiplier
)
expect(workerNode.workerUsage.tasks.queued).toBe(0)
+ expect(workerNode.workerUsage.tasks.maxQueued).toBe(1)
}
})
expect(queue.maxSize).toBe(3)
expect(queue.items).toStrictEqual([])
})
+
+ it('Verify clear() behavior', () => {
+ const queue = new Queue()
+ queue.enqueue(1)
+ queue.enqueue(2)
+ queue.enqueue(3)
+ expect(queue.size).toBe(3)
+ expect(queue.maxSize).toBe(3)
+ queue.clear()
+ expect(queue.size).toBe(0)
+ expect(queue.maxSize).toBe(0)
+ expect(queue.items).toStrictEqual([])
+ expect(queue.offset).toBe(0)
+ })
})