X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-busy-worker-choice-strategy.ts;h=8db32ac7f1421330e36d9bfb81bddf53392a666c;hb=98f60ddd83d32e108adcfddebeb902f0d5a197eb;hp=81cadde164c9d4371179546fe6fff1a275bba5a7;hpb=1ed7fb6c99f2fcb5f319d9c1fa2aefc5434f82e4;p=poolifier.git diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index 81cadde1..8db32ac7 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -1,15 +1,12 @@ -import { - DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, - DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS -} from '../../utils' -import type { IPool } from '../pool' -import type { IWorker } from '../worker' -import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' +import type { IPool } from '../pool.js' +import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' +import type { IWorker } from '../worker.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, TaskStatisticsRequirements, WorkerChoiceStrategyOptions -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the least busy worker. @@ -43,7 +40,7 @@ export class LeastBusyWorkerChoiceStrategy< /** @inheritDoc */ public constructor ( pool: IPool, - opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS + opts?: WorkerChoiceStrategyOptions ) { super(pool, opts) this.setTaskStatisticsRequirements(this.opts) @@ -72,6 +69,9 @@ export class LeastBusyWorkerChoiceStrategy< } private leastBusyNextWorkerNodeKey (): number | undefined { + if (this.pool.workerNodes.length === 0) { + return undefined + } return this.pool.workerNodes.reduce( (minWorkerNodeKey, workerNode, workerNodeKey, workerNodes) => { return this.isWorkerNodeReady(workerNodeKey) &&