Data = unknown,
Response = unknown
> implements IWorkerChoiceStrategy {
+ /**
+ * Toggles finding the last free worker node key.
+ */
+ private toggleFindLastFreeWorkerNodeKey: boolean = false
/** @inheritDoc */
protected readonly isDynamicPool: boolean
/** @inheritDoc */
*/
public constructor (
protected readonly pool: IPool<Worker, Data, Response>,
- protected readonly opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ protected opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
this.isDynamicPool = this.pool.type === PoolType.DYNAMIC
- this.choose.bind(this)
+ this.choose = this.choose.bind(this)
}
protected checkOptions (opts: WorkerChoiceStrategyOptions): void {
this.requiredStatistics.avgRunTime = false
this.requiredStatistics.medRunTime = opts.medRunTime as boolean
}
+ if (this.requiredStatistics.medRunTime && opts.medRunTime === false) {
+ this.requiredStatistics.avgRunTime = true
+ this.requiredStatistics.medRunTime = opts.medRunTime as boolean
+ }
}
/** @inheritDoc */
/** @inheritDoc */
public abstract remove (workerNodeKey: number): boolean
+
+ /** @inheritDoc */
+ public setOptions (opts: WorkerChoiceStrategyOptions): void {
+ opts = opts ?? DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ this.checkOptions(opts)
+ this.opts = opts
+ }
+
+ /**
+ * Finds a free worker node key.
+ *
+ * @returns The free worker node key or `-1` if there is no free worker node.
+ */
+ protected findFreeWorkerNodeKey (): number {
+ if (this.toggleFindLastFreeWorkerNodeKey) {
+ this.toggleFindLastFreeWorkerNodeKey = false
+ return this.pool.findLastFreeWorkerNodeKey()
+ }
+ this.toggleFindLastFreeWorkerNodeKey = true
+ return this.pool.findFreeWorkerNodeKey()
+ }
}