fix: ensure worker removal impact is propated to worker choice strategy
[poolifier.git] / src / pools / selection-strategies / fair-share-worker-choice-strategy.ts
index af8eb75d03995d1eb37eeb8daf8d44a8cb6d9d70..dbe10ce7181355fbf56a35c42551721f592efba2 100644 (file)
@@ -60,6 +60,17 @@ export class FairShareWorkerChoiceStrategy<
     return chosenWorkerKey
   }
 
+  /** {@inheritDoc} */
+  public remove (workerKey: number): boolean {
+    const workerDeleted = this.workerLastVirtualTaskTimestamp.delete(workerKey)
+    for (const [key, value] of this.workerLastVirtualTaskTimestamp.entries()) {
+      if (key > workerKey) {
+        this.workerLastVirtualTaskTimestamp.set(key - 1, value)
+      }
+    }
+    return workerDeleted
+  }
+
   /**
    * Computes worker last virtual task timestamp.
    *