feat: expose the number of strategy retries in pool info
[poolifier.git] / src / pools / selection-strategies / worker-choice-strategy-context.ts
index 40e2e18f303122685c70eb09e824175ab5309cef..d3d2ae56004c37698c5c7b0e055e27b3725f4c7e 100644 (file)
@@ -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)
   }
 
@@ -189,7 +195,8 @@ export class WorkerChoiceStrategyContext<
     do {
       workerNodeKey = workerChoiceStrategy.choose()
       if (workerNodeKey == null && chooseCount > 0) {
-        retriesCount++
+        ++retriesCount
+        ++this.retriesCount
       }
       chooseCount++
     } while (workerNodeKey == null && retriesCount < this.retries)