-import type { IPoolWorker } from '../pool-worker'
-
/**
* Enumeration of worker choice strategies.
*/
export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
/**
- * Pool tasks usage statistics requirements.
+ * Worker choice strategy options.
*/
-export interface RequiredStatistics {
- runTime: boolean
+export interface WorkerChoiceStrategyOptions {
+ /**
+ * Use tasks median run time instead of average run time.
+ */
+ medRunTime?: boolean
}
/**
- * Worker choice strategy interface.
+ * Pool worker tasks usage statistics requirements.
*
- * @typeParam Worker - Type of worker which manages the strategy.
+ * @internal
*/
-export interface IWorkerChoiceStrategy<Worker extends IPoolWorker> {
+export interface RequiredStatistics {
/**
- * Is the pool attached to the strategy dynamic?.
+ * Require tasks run time.
*/
- readonly isDynamicPool: boolean
+ runTime: boolean
/**
- * Required pool tasks usage statistics.
+ * Require tasks average run time.
+ */
+ avgRunTime: boolean
+ /**
+ * Require tasks median run time.
+ */
+ medRunTime: boolean
+}
+
+/**
+ * Worker choice strategy interface.
+ */
+export interface IWorkerChoiceStrategy {
+ /**
+ * Required tasks usage statistics.
*/
readonly requiredStatistics: RequiredStatistics
/**
*/
reset: () => boolean
/**
- * Chooses a worker in the pool.
+ * Chooses a worker node in the pool and returns its key.
+ */
+ choose: () => number
+ /**
+ * Removes a worker node key from strategy internals.
+ *
+ * @param workerNodeKey - The worker node key.
+ */
+ remove: (workerNodeKey: number) => boolean
+ /**
+ * Sets the worker choice strategy options.
+ *
+ * @param opts - The worker choice strategy options.
*/
- choose: () => Worker
+ setOptions: (opts: WorkerChoiceStrategyOptions) => void
}