import type { IPool } from '../pool.js'
+import { getWorkerChoiceStrategyRetries } from '../utils.js'
import type { IWorker } from '../worker.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'
-import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy.js'
import { LeastEluWorkerChoiceStrategy } from './least-elu-worker-choice-strategy.js'
+import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy.js'
import { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
Data = unknown,
Response = unknown
> {
+ /**
+ * The number of worker choice strategy execution retries.
+ */
+ public retriesCount: number
+
/**
* The worker choice strategy instances registered in the context.
*/
>
/**
- * The number of worker choice strategy execution retries.
+ * The maximum number of worker choice strategy execution retries.
*/
private readonly retries: number
>(pool, opts)
]
])
+ this.retriesCount = 0
this.retries = getWorkerChoiceStrategyRetries(pool, opts)
}
let retriesCount = 0
do {
workerNodeKey = workerChoiceStrategy.choose()
- if (workerNodeKey != null && workerNodeKey < 0) {
- workerNodeKey = undefined
- }
if (workerNodeKey == null && chooseCount > 0) {
- retriesCount++
+ ++retriesCount
+ ++this.retriesCount
}
- chooseCount++
+ ++chooseCount
} while (workerNodeKey == null && retriesCount < this.retries)
if (workerNodeKey == null) {
throw new Error(