private setTaskStealing (): void {
for (const [workerNodeKey] of this.workerNodes.entries()) {
this.workerNodes[workerNodeKey].addEventListener(
- 'emptyqueue',
+ 'emptyQueue',
this.handleEmptyQueueEvent as EventListener
)
}
private unsetTaskStealing (): void {
for (const [workerNodeKey] of this.workerNodes.entries()) {
this.workerNodes[workerNodeKey].removeEventListener(
- 'emptyqueue',
+ 'emptyQueue',
this.handleEmptyQueueEvent as EventListener
)
}
private setTasksStealingOnBackPressure (): void {
for (const [workerNodeKey] of this.workerNodes.entries()) {
this.workerNodes[workerNodeKey].addEventListener(
- 'backpressure',
+ 'backPressure',
this.handleBackPressureEvent as EventListener
)
}
private unsetTasksStealingOnBackPressure (): void {
for (const [workerNodeKey] of this.workerNodes.entries()) {
this.workerNodes[workerNodeKey].removeEventListener(
- 'backpressure',
+ 'backPressure',
this.handleBackPressureEvent as EventListener
)
}
if (this.opts.enableTasksQueue === true) {
if (this.opts.tasksQueueOptions?.taskStealing === true) {
this.workerNodes[workerNodeKey].addEventListener(
- 'emptyqueue',
+ 'emptyQueue',
this.handleEmptyQueueEvent as EventListener
)
}
if (this.opts.tasksQueueOptions?.tasksStealingOnBackPressure === true) {
this.workerNodes[workerNodeKey].addEventListener(
- 'backpressure',
+ 'backPressure',
this.handleBackPressureEvent as EventListener
)
}
private readonly handleEmptyQueueEvent = (
event: CustomEvent<WorkerNodeEventDetail>
): void => {
- const destinationWorkerNodeKey = this.getWorkerNodeKeyByWorkerId(
- event.detail.workerId
- )
+ const { workerId } = event.detail
+ const destinationWorkerNodeKey = this.getWorkerNodeKeyByWorkerId(workerId)
const workerNodes = this.workerNodes
.slice()
.sort(
const sourceWorkerNode = workerNodes.find(
workerNode =>
workerNode.info.ready &&
- workerNode.info.id !== event.detail.workerId &&
+ workerNode.info.id !== workerId &&
workerNode.usage.tasks.queued > 0
)
if (sourceWorkerNode != null) {
private readonly handleBackPressureEvent = (
event: CustomEvent<WorkerNodeEventDetail>
): void => {
+ const { workerId } = event.detail
const sizeOffset = 1
if ((this.opts.tasksQueueOptions?.size as number) <= sizeOffset) {
return
}
const sourceWorkerNode =
- this.workerNodes[this.getWorkerNodeKeyByWorkerId(event.detail.workerId)]
+ this.workerNodes[this.getWorkerNodeKeyByWorkerId(workerId)]
const workerNodes = this.workerNodes
.slice()
.sort(
if (
sourceWorkerNode.usage.tasks.queued > 0 &&
workerNode.info.ready &&
- workerNode.info.id !== event.detail.workerId &&
+ workerNode.info.id !== workerId &&
workerNode.usage.tasks.queued <
(this.opts.tasksQueueOptions?.size as number) - sizeOffset
) {
if (this.hasBackPressure() && !this.onBackPressureStarted) {
this.onBackPressureStarted = true
this.dispatchEvent(
- new CustomEvent<WorkerNodeEventDetail>('backpressure', {
+ new CustomEvent<WorkerNodeEventDetail>('backPressure', {
detail: { workerId: this.info.id as number }
})
)
if (this.hasBackPressure() && !this.onBackPressureStarted) {
this.onBackPressureStarted = true
this.dispatchEvent(
- new CustomEvent<WorkerNodeEventDetail>('backpressure', {
+ new CustomEvent<WorkerNodeEventDetail>('backPressure', {
detail: { workerId: this.info.id as number }
})
)
}
++this.onEmptyQueueCount
this.dispatchEvent(
- new CustomEvent<WorkerNodeEventDetail>('emptyqueue', {
+ new CustomEvent<WorkerNodeEventDetail>('emptyQueue', {
detail: { workerId: this.info.id as number }
})
)