X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=3c41dd6ffee305c8eb2f51f593df022d8889745b;hb=64f97d12e2027203715ee0129d036e1d2b42e2a2;hp=4ed7dcae2b0dea882d1eb15a1cb0f88310435e7f;hpb=936fa0fb8e70b2c297938cc9455444486b6daa3e;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 4ed7dcae..3c41dd6f 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -30,10 +30,15 @@ export abstract class AbstractWorkerChoiceStrategy< */ protected nextWorkerNodeKey: number | undefined = 0 + /** + * The previous worker node key. + */ + protected previousWorkerNodeKey: number = 0 + /** @inheritDoc */ public readonly strategyPolicy: StrategyPolicy = { dynamicWorkerUsage: false, - dynamicWorkerReady: false + dynamicWorkerReady: true } /** @inheritDoc */ @@ -88,6 +93,11 @@ export abstract class AbstractWorkerChoiceStrategy< } } + protected resetWorkerNodeKeyProperties (): void { + this.nextWorkerNodeKey = 0 + this.previousWorkerNodeKey = 0 + } + /** @inheritDoc */ public abstract reset (): boolean @@ -185,16 +195,19 @@ export abstract class AbstractWorkerChoiceStrategy< } /** - * Assign to nextWorkerNodeKey property the chosen worker node key. + * Sets safely the previous worker node key. * - * @param chosenWorkerNodeKey - The chosen worker node key. + * @param workerNodeKey - The worker node key. */ - protected assignChosenWorkerNodeKey ( - chosenWorkerNodeKey: number | undefined - ): void { - if (chosenWorkerNodeKey != null) { - this.nextWorkerNodeKey = chosenWorkerNodeKey - } else { + protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void { + this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey + } + + /** + * Check the next worker node eligibility. + */ + protected checkNextWorkerNodeEligibility (): void { + if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { this.nextWorkerNodeKey = undefined } }