X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=f244374291da55b9173129b6384b00f49d952e65;hb=0e8587d2e6bc29e14158c01948c625df9b11d381;hp=0a2b6113b8451bfabfd7fc866d59cc71b2f95ef2;hpb=04d875a3942abe97ce35c177c6e6f41619be974b;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 0a2b6113..f2443742 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -32,7 +32,7 @@ export abstract class AbstractWorkerChoiceStrategy< /** * The previous worker node key. */ - protected previousWorkerNodeKey: number = 0 + protected previousWorkerNodeKey = 0 /** @inheritDoc */ public readonly strategyPolicy: StrategyPolicy = { @@ -132,11 +132,14 @@ export abstract class AbstractWorkerChoiceStrategy< } /** - * Check the next worker node readiness. + * Check the next worker node key. */ - protected checkNextWorkerNodeReadiness (): void { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - if (!this.isWorkerNodeReady(this.nextWorkerNodeKey!)) { + protected checkNextWorkerNodeKey (): void { + if ( + this.nextWorkerNodeKey != null && + (this.nextWorkerNodeKey < 0 || + !this.isWorkerNodeReady(this.nextWorkerNodeKey)) + ) { delete this.nextWorkerNodeKey } } @@ -189,6 +192,9 @@ export abstract class AbstractWorkerChoiceStrategy< * @param workerNodeKey - The worker node key. */ protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void { - this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey + this.previousWorkerNodeKey = + workerNodeKey != null && workerNodeKey >= 0 + ? workerNodeKey + : this.previousWorkerNodeKey } }