X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=eaa03f3d51b44e749798f55ec54315845322c54f;hb=915040cce0e378cc1e806391bf77af06880c12f2;hp=d8d8f32d2f9dc2eee45f63c75f2aa0ece167b108;hpb=ce63d9e2f3d895bd2ae5aafc40769ff4dda3c887;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 d8d8f32d..eaa03f3d 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -1,8 +1,5 @@ -import { - DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, - buildWorkerChoiceStrategyOptions -} from '../../utils.js' import type { IPool } from '../pool.js' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' import type { IWorker } from '../worker.js' import type { IWorkerChoiceStrategy, @@ -11,6 +8,7 @@ import type { TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types.js' +import { buildWorkerChoiceStrategyOptions } from './selection-strategies-utils.js' /** * Worker choice strategy abstract base class. @@ -32,7 +30,7 @@ export abstract class AbstractWorkerChoiceStrategy< /** * The previous worker node key. */ - protected previousWorkerNodeKey: number = 0 + protected previousWorkerNodeKey = 0 /** @inheritDoc */ public readonly strategyPolicy: StrategyPolicy = { @@ -57,8 +55,8 @@ export abstract class AbstractWorkerChoiceStrategy< protected readonly pool: IPool, protected opts?: WorkerChoiceStrategyOptions ) { - this.setOptions(this.opts) this.choose = this.choose.bind(this) + this.setOptions(this.opts) } protected setTaskStatisticsRequirements ( @@ -121,11 +119,6 @@ export abstract class AbstractWorkerChoiceStrategy< this.setTaskStatisticsRequirements(this.opts) } - /** @inheritDoc */ - public hasPoolWorkerNodesReady (): boolean { - return this.pool.workerNodes.some(workerNode => workerNode.info.ready) - } - /** * Whether the worker node is ready or not. * @@ -137,11 +130,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 } } @@ -194,6 +190,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 } }