- public choose (): Worker {
- const currentWorker = this.pool.workers[this.currentWorkerIndex]
- if (
- this.isDynamicPool === true &&
- this.workersTaskRunTime.has(currentWorker) === false
- ) {
- this.initWorkerTaskRunTime(currentWorker)
- }
- const workerVirtualTaskRunTime =
- this.getWorkerVirtualTaskRunTime(currentWorker) ?? 0
- const workerTaskWeight =
- this.workersTaskRunTime.get(currentWorker)?.weight ??
- this.defaultWorkerWeight
- if (this.currentWorkerIndex === this.previousWorkerIndex) {
- const workerTaskRunTime =
- (this.workersTaskRunTime.get(currentWorker)?.runTime ?? 0) +
- workerVirtualTaskRunTime
- this.setWorkerTaskRunTime(
- currentWorker,
- workerTaskWeight,
- workerTaskRunTime
- )
- } else {
- this.setWorkerTaskRunTime(currentWorker, workerTaskWeight, 0)
- }
- if (workerVirtualTaskRunTime < workerTaskWeight) {
- this.previousWorkerIndex = this.currentWorkerIndex
+ public update (): boolean {
+ return true
+ }
+
+ /** @inheritDoc */
+ public choose (): number {
+ const chosenWorkerNodeKey = this.currentWorkerNodeId
+ const workerVirtualTaskRunTime = this.workerVirtualTaskRunTime
+ const workerWeight =
+ this.opts.weights?.[chosenWorkerNodeKey] ?? this.defaultWorkerWeight
+ if (workerVirtualTaskRunTime < workerWeight) {
+ this.workerVirtualTaskRunTime =
+ workerVirtualTaskRunTime +
+ this.getWorkerTaskRunTime(chosenWorkerNodeKey)