- public choose (): Worker {
- let chosenWorker = this.pool.workers[this.currentWorkerIndex]
- if (
- this.isDynamicPool === true &&
- this.workersTaskRunTime.has(chosenWorker) === false
- ) {
- this.initWorkerTaskRunTime(chosenWorker)
- }
- const workerTaskWeight =
- this.workersTaskRunTime.get(chosenWorker)?.weight ??
- this.defaultWorkerWeight
- if (
- (this.workersTaskRunTime.get(chosenWorker)?.runTime ?? 0) <
- workerTaskWeight
- ) {
- this.setWorkerTaskRunTime(
- chosenWorker,
- workerTaskWeight,
- (this.workersTaskRunTime.get(chosenWorker)?.runTime ?? 0) +
- (this.getWorkerVirtualTaskRunTime(chosenWorker) ?? 0)
- )
+ 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.getWorkerVirtualTaskRunTime(chosenWorkerNodeKey)