From: Jérôme Benoit Date: Tue, 11 Jul 2023 14:56:02 +0000 (+0200) Subject: feat: make the remaining worker choice strategies worker readiness aware X-Git-Tag: v2.6.15~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=949194eb4b838e9d22dcc4d16649521f7b9e79c3;p=poolifier.git feat: make the remaining worker choice strategies worker readiness aware Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 063e40d2..a3b46cee 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1135,6 +1135,7 @@ export abstract class AbstractPool< */ private pushWorkerNode (worker: Worker): number { const workerNode = new WorkerNode(worker, this.worker) + // Flag the worker as ready at pool startup. if (this.starting) { workerNode.info.ready = true } diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 222a0349..b023234a 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -50,7 +50,9 @@ export class RoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { const chosenWorkerNodeKey = this.nextWorkerNodeKey - this.roundRobinNextWorkerNodeKey() + do { + this.roundRobinNextWorkerNodeKey() + } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey)) return chosenWorkerNodeKey } diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 4921df6d..fecba414 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -77,7 +77,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { const chosenWorkerNodeKey = this.nextWorkerNodeKey - this.weightedRoundRobinNextWorkerNodeKey() + do { + this.weightedRoundRobinNextWorkerNodeKey() + } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey)) return chosenWorkerNodeKey }