X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Ffair-share-worker-choice-strategy.ts;h=c4a0d30beb7fe827d614ca9f434c7470aeb9d018;hb=7790a494fdff6a2152b3153d02c9fbe8de11ed93;hp=bf30a4764d4ffdd5287fcbbad588baddca42b193;hpb=20016c79549983d09d30b70852ec7fae515d4156;p=poolifier.git diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index bf30a476..c4a0d30b 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -69,8 +69,10 @@ export class FairShareWorkerChoiceStrategy< } /** @inheritDoc */ - public choose (): number { - return this.fairShareNextWorkerNodeKey() + public choose (): number | undefined { + this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey) + this.nextWorkerNodeKey = this.fairShareNextWorkerNodeKey() + return this.nextWorkerNodeKey } /** @inheritDoc */ @@ -79,7 +81,8 @@ export class FairShareWorkerChoiceStrategy< return true } - private fairShareNextWorkerNodeKey (): number { + private fairShareNextWorkerNodeKey (): number | undefined { + let chosenWorkerNodeKey: number | undefined let minWorkerVirtualTaskEndTimestamp = Infinity for (const [workerNodeKey] of this.pool.workerNodes.entries()) { if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) { @@ -87,15 +90,12 @@ export class FairShareWorkerChoiceStrategy< } const workerVirtualTaskEndTimestamp = this.workersVirtualTaskEndTimestamp[workerNodeKey] - if ( - this.isWorkerNodeReady(workerNodeKey) && - workerVirtualTaskEndTimestamp < minWorkerVirtualTaskEndTimestamp - ) { + if (workerVirtualTaskEndTimestamp < minWorkerVirtualTaskEndTimestamp) { minWorkerVirtualTaskEndTimestamp = workerVirtualTaskEndTimestamp - this.nextWorkerNodeKey = workerNodeKey + chosenWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeKey + return chosenWorkerNodeKey } /**