+import type { IPool } from '../pool.js'
import {
DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
- buildInternalWorkerChoiceStrategyOptions
-} from '../../utils'
-import type { IPool } from '../pool'
-import type { IWorker } from '../worker'
+ buildWorkerChoiceStrategyOptions
+} from '../utils.js'
+import type { IWorker } from '../worker.js'
import type {
IWorkerChoiceStrategy,
- InternalWorkerChoiceStrategyOptions,
MeasurementStatisticsRequirements,
StrategyPolicy,
- TaskStatisticsRequirements
-} from './selection-strategies-types'
+ TaskStatisticsRequirements,
+ WorkerChoiceStrategyOptions
+} from './selection-strategies-types.js'
/**
* Worker choice strategy abstract base class.
/**
* The previous worker node key.
*/
- protected previousWorkerNodeKey: number = 0
+ protected previousWorkerNodeKey = 0
/** @inheritDoc */
public readonly strategyPolicy: StrategyPolicy = {
*/
public constructor (
protected readonly pool: IPool<Worker, Data, Response>,
- protected opts: InternalWorkerChoiceStrategyOptions
+ protected opts?: WorkerChoiceStrategyOptions
) {
- this.setOptions(this.opts)
this.choose = this.choose.bind(this)
+ this.setOptions(this.opts)
}
protected setTaskStatisticsRequirements (
- opts: InternalWorkerChoiceStrategyOptions
+ opts: WorkerChoiceStrategyOptions | undefined
): void {
this.toggleMedianMeasurementStatisticsRequirements(
this.taskStatisticsRequirements.runTime,
- opts.runTime?.median as boolean
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ opts!.runTime!.median
)
this.toggleMedianMeasurementStatisticsRequirements(
this.taskStatisticsRequirements.waitTime,
- opts.waitTime?.median as boolean
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ opts!.waitTime!.median
)
this.toggleMedianMeasurementStatisticsRequirements(
this.taskStatisticsRequirements.elu,
- opts.elu?.median as boolean
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ opts!.elu!.median
)
}
public abstract remove (workerNodeKey: number): boolean
/** @inheritDoc */
- public setOptions (opts: InternalWorkerChoiceStrategyOptions): void {
- this.opts = buildInternalWorkerChoiceStrategyOptions(
- this.pool.info.maxSize,
+ public setOptions (opts: WorkerChoiceStrategyOptions | undefined): void {
+ this.opts = buildWorkerChoiceStrategyOptions<Worker, Data, Response>(
+ this.pool,
opts
)
this.setTaskStatisticsRequirements(this.opts)
}
- /** @inheritDoc */
- public hasPoolWorkerNodesReady (): boolean {
- return this.pool.workerNodes.some(workerNode => workerNode.info.ready)
- }
-
/**
* Whether the worker node is ready or not.
*
}
/**
- * Check the next worker node readiness.
+ * Check the next worker node key.
*/
- protected checkNextWorkerNodeReadiness (): void {
- if (!this.isWorkerNodeReady(this.nextWorkerNodeKey as number)) {
+ protected checkNextWorkerNodeKey (): void {
+ if (
+ this.nextWorkerNodeKey != null &&
+ (this.nextWorkerNodeKey < 0 ||
+ !this.isWorkerNodeReady(this.nextWorkerNodeKey))
+ ) {
delete this.nextWorkerNodeKey
}
}
* @param workerNodeKey - The worker node key.
*/
protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void {
- this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey
+ this.previousWorkerNodeKey =
+ workerNodeKey != null && workerNodeKey >= 0
+ ? workerNodeKey
+ : this.previousWorkerNodeKey
}
}