+ /** @inheritDoc */
+ public abstract update (workerNodeKey: number): boolean
+
+ /** @inheritDoc */
+ public abstract choose (): number | undefined
+
+ /** @inheritDoc */
+ public abstract remove (workerNodeKey: number): boolean
+
+ /** @inheritDoc */
+ public setOptions (opts: WorkerChoiceStrategyOptions | undefined): void {
+ this.opts = buildWorkerChoiceStrategyOptions<Worker, Data, Response>(
+ this.pool,
+ opts
+ )
+ this.setTaskStatisticsRequirements(this.opts)
+ }
+
+ /**
+ * Whether the worker node is ready or not.
+ *
+ * @param workerNodeKey - The worker node key.
+ * @returns Whether the worker node is ready or not.
+ */
+ protected isWorkerNodeReady (workerNodeKey: number): boolean {
+ return this.pool.workerNodes[workerNodeKey]?.info?.ready ?? false
+ }
+
+ /**
+ * Check the next worker node key.
+ */
+ protected checkNextWorkerNodeKey (): void {
+ if (
+ this.nextWorkerNodeKey != null &&
+ (this.nextWorkerNodeKey < 0 ||
+ !this.isWorkerNodeReady(this.nextWorkerNodeKey))
+ ) {
+ delete this.nextWorkerNodeKey
+ }
+ }
+
+ /**
+ * 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 node task runtime.
+ */
+ 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
+ }