X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.ts;h=fc940a2fbb0f7d85ec450cc35beb60cab75cd141;hb=935f8249773187a56ea8d741e783e8929b5038f1;hp=46e7ac64221d500f87f7d344c4687849bb0361df;hpb=e44639e9af74427b71f1556ff7ec9f7606373e0d;p=poolifier.git diff --git a/src/pools/selection-strategies/worker-choice-strategy-context.ts b/src/pools/selection-strategies/worker-choice-strategy-context.ts index 46e7ac64..fc940a2f 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -1,6 +1,6 @@ import type { IPool } from '../pool.js' import type { IWorker } from '../worker.js' -import { getWorkerChoiceStrategyRetries } from '../../utils.js' +import { getWorkerChoiceStrategyRetries } from '../utils.js' import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy.js' import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from './interleaved-weighted-round-robin-worker-choice-strategy.js' import { LeastBusyWorkerChoiceStrategy } from './least-busy-worker-choice-strategy.js' @@ -29,6 +29,11 @@ export class WorkerChoiceStrategyContext< Data = unknown, Response = unknown > { + /** + * The number of worker choice strategy execution retries. + */ + public retriesCount: number + /** * The worker choice strategy instances registered in the context. */ @@ -38,7 +43,7 @@ export class WorkerChoiceStrategyContext< > /** - * The number of worker choice strategy execution retries. + * The maximum number of worker choice strategy execution retries. */ private readonly retries: number @@ -111,6 +116,7 @@ export class WorkerChoiceStrategyContext< >(pool, opts) ] ]) + this.retriesCount = 0 this.retries = getWorkerChoiceStrategyRetries(pool, opts) } @@ -166,7 +172,7 @@ export class WorkerChoiceStrategyContext< * Executes the worker choice strategy in the context algorithm. * * @returns The key of the worker node. - * @throws {@link https://nodejs.org/api/errors.html#class-error} If after configured retries the worker node key is null or undefined. + * @throws {@link https://nodejs.org/api/errors.html#class-error} If after computed retries the worker node key is null or undefined. */ public execute (): number { return this.executeStrategy( @@ -189,9 +195,10 @@ export class WorkerChoiceStrategyContext< do { workerNodeKey = workerChoiceStrategy.choose() if (workerNodeKey == null && chooseCount > 0) { - retriesCount++ + ++retriesCount + ++this.retriesCount } - chooseCount++ + ++chooseCount } while (workerNodeKey == null && retriesCount < this.retries) if (workerNodeKey == null) { throw new Error(