- public choose (): number {
- const chosenWorkerNodeKey = this.currentWorkerNodeId
- if (
- this.isDynamicPool &&
- !this.workersTaskRunTime.has(chosenWorkerNodeKey)
- ) {
- this.initWorkerTaskRunTime(chosenWorkerNodeKey)
- }
- const workerTaskRunTime =
- this.workersTaskRunTime.get(chosenWorkerNodeKey)?.runTime ?? 0
- const workerTaskWeight =
- this.workersTaskRunTime.get(chosenWorkerNodeKey)?.weight ??
- this.defaultWorkerWeight
- if (workerTaskRunTime < workerTaskWeight) {
- this.setWorkerTaskRunTime(
- chosenWorkerNodeKey,
- workerTaskWeight,
- workerTaskRunTime +
- (this.getWorkerVirtualTaskRunTime(chosenWorkerNodeKey) ?? 0)
- )
- } else {
- this.currentWorkerNodeId =
- this.currentWorkerNodeId === this.pool.workerNodes.length - 1
- ? 0
- : this.currentWorkerNodeId + 1
- this.setWorkerTaskRunTime(this.currentWorkerNodeId, workerTaskWeight, 0)
- }
- return chosenWorkerNodeKey
+ public update (): boolean {
+ return true
+ }
+
+ /** @inheritDoc */
+ public choose (): number | undefined {
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
+ return this.weightedRoundRobinNextWorkerNodeKey()