X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=999d9c866cd46aebc168cadf9408dc86ec8c0c0d;hb=946b809b91118cd7442b90971344e53e15c26466;hp=cc38d196941e4611af2235a84899cd82ab55c9f0;hpb=46e29227a97fe04f886969199f1c14338af50543;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 cc38d196..999d9c86 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -93,6 +93,11 @@ export abstract class AbstractWorkerChoiceStrategy< } } + protected resetWorkerNodeKeyProperties (): void { + this.nextWorkerNodeKey = 0 + this.previousWorkerNodeKey = 0 + } + /** @inheritDoc */ public abstract reset (): boolean @@ -148,69 +153,62 @@ export abstract class AbstractWorkerChoiceStrategy< } /** - * Gets the worker task runtime. + * Gets the worker node task runtime. * If the task statistics require the average runtime, the average runtime is returned. * If the task statistics require the median runtime , the median runtime is returned. * * @param workerNodeKey - The worker node key. - * @returns The worker task runtime. + * @returns The worker node task runtime. */ - protected getWorkerTaskRunTime (workerNodeKey: number): number { + protected getWorkerNodeTaskRunTime (workerNodeKey: number): number { return this.taskStatisticsRequirements.runTime.median - ? this.pool.workerNodes[workerNodeKey].usage.runTime?.median ?? 0 - : this.pool.workerNodes[workerNodeKey].usage.runTime?.average ?? 0 + ? this.pool.workerNodes[workerNodeKey]?.usage?.runTime?.median ?? 0 + : this.pool.workerNodes[workerNodeKey]?.usage?.runTime?.average ?? 0 } /** - * Gets the worker task wait time. + * Gets the worker node task wait time. * If the task statistics require the average wait time, the average wait time is returned. * If the task statistics require the median wait time, the median wait time is returned. * * @param workerNodeKey - The worker node key. - * @returns The worker task wait time. + * @returns The worker node task wait time. */ - protected getWorkerTaskWaitTime (workerNodeKey: number): number { + protected getWorkerNodeTaskWaitTime (workerNodeKey: number): number { return this.taskStatisticsRequirements.waitTime.median - ? this.pool.workerNodes[workerNodeKey].usage.waitTime?.median ?? 0 - : this.pool.workerNodes[workerNodeKey].usage.waitTime?.average ?? 0 + ? this.pool.workerNodes[workerNodeKey]?.usage?.waitTime?.median ?? 0 + : this.pool.workerNodes[workerNodeKey]?.usage?.waitTime?.average ?? 0 } /** - * Gets the worker task ELU. + * Gets the worker node task ELU. * If the task statistics require the average ELU, the average ELU is returned. * If the task statistics require the median ELU, the median ELU is returned. * * @param workerNodeKey - The worker node key. - * @returns The worker task ELU. + * @returns The worker node task ELU. */ - protected getWorkerTaskElu (workerNodeKey: number): number { + protected getWorkerNodeTaskElu (workerNodeKey: number): number { return this.taskStatisticsRequirements.elu.median - ? this.pool.workerNodes[workerNodeKey].usage.elu.active?.median ?? 0 - : this.pool.workerNodes[workerNodeKey].usage.elu.active?.average ?? 0 + ? this.pool.workerNodes[workerNodeKey]?.usage?.elu?.active?.median ?? 0 + : this.pool.workerNodes[workerNodeKey]?.usage?.elu?.active?.average ?? 0 } /** - * Assign to nextWorkerNodeKey property the chosen worker node key. + * Sets safely the previous worker node key. * - * @param chosenWorkerNodeKey - The chosen worker node key. + * @param workerNodeKey - The worker node key. */ - protected assignChosenWorkerNodeKey ( - chosenWorkerNodeKey: number | undefined - ): void { - if (chosenWorkerNodeKey != null) { - this.nextWorkerNodeKey = chosenWorkerNodeKey - } else { - this.nextWorkerNodeKey = undefined - } + protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void { + this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey } - protected checkNextWorkerNodeEligibility ( - chosenWorkerNodeKey: number | undefined - ): void { + /** + * Check the next worker node eligibility. + */ + protected checkNextWorkerNodeEligibility (): void { if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { this.nextWorkerNodeKey = undefined - this.previousWorkerNodeKey = - chosenWorkerNodeKey ?? this.previousWorkerNodeKey } }