X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-used-worker-choice-strategy.ts;h=e45d57549580b883c1f6a185dc7701b861004336;hb=b358c8aca5934f7d5dc4bd234d1909ba13850ea9;hp=1bd8d059fd5f9bc40484db9bbece55d319eddcbc;hpb=1ed7fb6c99f2fcb5f319d9c1fa2aefc5434f82e4;p=poolifier.git diff --git a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts index 1bd8d059..e45d5754 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -1,11 +1,10 @@ -import { 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 type { IWorker } from '../worker.js' +import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, WorkerChoiceStrategyOptions -} from './selection-strategies-types' +} from './selection-strategies-types.js' /** * Selects the least used worker. @@ -24,10 +23,9 @@ export class LeastUsedWorkerChoiceStrategy< /** @inheritDoc */ public constructor ( pool: IPool, - opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS + opts?: WorkerChoiceStrategyOptions ) { super(pool, opts) - this.setTaskStatisticsRequirements(this.opts) } /** @inheritDoc */ @@ -53,6 +51,9 @@ export class LeastUsedWorkerChoiceStrategy< } private leastUsedNextWorkerNodeKey (): number | undefined { + if (this.pool.workerNodes.length === 0) { + return undefined + } return this.pool.workerNodes.reduce( (minWorkerNodeKey, workerNode, workerNodeKey, workerNodes) => { return this.isWorkerNodeReady(workerNodeKey) &&