X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=ca3d9b9d640fc6bf0faedfe3105d5751802281e1;hb=516dcb0df1957823ec30f15db5f7585a7a302e8f;hp=fb3bf707386f8bdb2bb9aac23ccf6db9d851ac96;hpb=f6bc9f26d8a0246bbee14b2b03d0bcc41b8aeb52;p=poolifier.git diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index fb3bf707..ca3d9b9d 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -93,6 +93,11 @@ export abstract class AbstractWorkerChoiceStrategy< } } + protected resetWorkerNodeKeyProperties (): void { + this.nextWorkerNodeKey = 0 + this.previousWorkerNodeKey = 0 + } + /** @inheritDoc */ public abstract reset (): boolean @@ -190,17 +195,25 @@ export abstract class AbstractWorkerChoiceStrategy< } /** - * Assign to nextWorkerNodeKey property the chosen worker node key. + * Sets safely the previous worker node key. + * + * @param workerNodeKey - The worker node key. + */ + protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void { + this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey + } + + /** + * Check the next worker node eligibility. * - * @param chosenWorkerNodeKey - The chosen worker node key. + * @param previousWorkerNodeKey - The previous worker node key. */ - protected assignChosenWorkerNodeKey ( - chosenWorkerNodeKey: number | undefined + protected checkNextWorkerNodeEligibility ( + previousWorkerNodeKey: number | undefined ): void { - if (chosenWorkerNodeKey != null) { - this.nextWorkerNodeKey = chosenWorkerNodeKey - } else { + if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { this.nextWorkerNodeKey = undefined + this.setPreviousWorkerNodeKey(previousWorkerNodeKey) } }