X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=ff1d4b0847e3bd53be4c06bd3d252523f3ff545e;hb=5ff840c7da44b209f1bab00f0881f7fc93e36eec;hp=55f43092d17760653168b59bee184fc508db1d54;hpb=799c9e089724b6402ae72e0a60719017055a6669;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 55f43092..ff1d4b08 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -1,8 +1,8 @@ +import type { IPool } from '../pool.js' import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, buildWorkerChoiceStrategyOptions -} from '../../utils.js' -import type { IPool } from '../pool.js' +} from '../utils.js' import type { IWorker } from '../worker.js' import type { IWorkerChoiceStrategy, @@ -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 } }