X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=cd8736c25e771470871497be2ef2f6933105aaa4;hb=aa1e0433fcfdc47175d6144524bcda57ab2947a1;hp=e6269422abb7b2e89d5021fc82ade5a443268b5d;hpb=8990357d855c45cd0063f24092bb58b4163ddb0a;p=poolifier.git diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index e6269422..cd8736c2 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -28,11 +28,17 @@ export abstract class AbstractWorkerChoiceStrategy< /** * The next worker node key. */ - protected nextWorkerNodeKey: number = 0 + protected nextWorkerNodeKey: number | undefined = 0 + + /** + * The previous worker node key. + */ + protected previousWorkerNodeKey: number = 0 /** @inheritDoc */ public readonly strategyPolicy: StrategyPolicy = { - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true } /** @inheritDoc */ @@ -87,6 +93,11 @@ export abstract class AbstractWorkerChoiceStrategy< } } + protected resetWorkerNodeKeyProperties (): void { + this.nextWorkerNodeKey = 0 + this.previousWorkerNodeKey = 0 + } + /** @inheritDoc */ public abstract reset (): boolean @@ -94,7 +105,7 @@ export abstract class AbstractWorkerChoiceStrategy< public abstract update (workerNodeKey: number): boolean /** @inheritDoc */ - public abstract choose (): number + public abstract choose (): number | undefined /** @inheritDoc */ public abstract remove (workerNodeKey: number): boolean @@ -183,6 +194,21 @@ export abstract class AbstractWorkerChoiceStrategy< : this.pool.workerNodes[workerNodeKey].usage.elu.active?.average ?? 0 } + /** + * Check the next worker node eligibility. + * + * @param chosenNextWorkerNodeKey - The chosen next worker node key. + */ + protected checkNextWorkerNodeEligibility ( + chosenNextWorkerNodeKey: number | undefined + ): void { + if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { + this.nextWorkerNodeKey = undefined + this.previousWorkerNodeKey = + chosenNextWorkerNodeKey ?? this.previousWorkerNodeKey + } + } + protected computeDefaultWorkerWeight (): number { let cpusCycleTimeWeight = 0 for (const cpu of cpus()) {