X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Finterleaved-weighted-round-robin-worker-choice-strategy.ts;h=3942bb6ed99961f986e1286ab20b31baf2a00eb5;hb=8166b5b31ebb2d15bbdc112f1a86d3774fe21294;hp=0f718e9817159bd6aedb5012e3246786d4696f50;hpb=ab3bb4a4fd6b09465fb97ec4f412e57448f94306;p=poolifier.git diff --git a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts index 0f718e98..3942bb6e 100644 --- a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts @@ -1,12 +1,12 @@ -import type { IWorker } from '../worker' -import type { IPool } from '../pool' -import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import type { IWorker } from '../worker.js' +import type { IPool } from '../pool.js' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, - InternalWorkerChoiceStrategyOptions, - TaskStatisticsRequirements -} from './selection-strategies-types' + TaskStatisticsRequirements, + WorkerChoiceStrategyOptions +} from './selection-strategies-types.js' /** * Selects the next worker with an interleaved weighted round robin scheduling algorithm. @@ -40,7 +40,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< /** * Round weights. */ - private roundWeights!: number[] + private roundWeights: number[] /** * Worker node id. */ @@ -53,10 +53,11 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public constructor ( pool: IPool, - opts: InternalWorkerChoiceStrategyOptions + opts?: WorkerChoiceStrategyOptions ) { super(pool, opts) - this.setOptions(this.opts) + this.setTaskStatisticsRequirements(this.opts) + this.roundWeights = this.getRoundWeights() } /** @inheritDoc */ @@ -93,7 +94,8 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< ) { this.workerNodeVirtualTaskRunTime = 0 } - const workerWeight = this.opts.weights?.[workerNodeKey] as number + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const workerWeight = this.opts!.weights![workerNodeKey]! if ( this.isWorkerNodeReady(workerNodeKey) && workerWeight >= this.roundWeights[roundIndex] && @@ -147,7 +149,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< } /** @inheritDoc */ - public setOptions (opts: InternalWorkerChoiceStrategyOptions): void { + public setOptions (opts: WorkerChoiceStrategyOptions | undefined): void { super.setOptions(opts) this.roundWeights = this.getRoundWeights() } @@ -155,7 +157,8 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< private getRoundWeights (): number[] { return [ ...new Set( - Object.values(this.opts.weights as Record) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + Object.values(this.opts!.weights!) .slice() .sort((a, b) => a - b) )