refactor: rename a worker choice strategy
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
CommitLineData
ea7a90d3 1import type { IPoolWorker } from '../pool-worker'
bdaf31cd
JB
2
3/**
4 * Enumeration of worker choice strategies.
5 */
6export const WorkerChoiceStrategies = Object.freeze({
7 /**
8 * Round robin worker selection strategy.
9 */
10 ROUND_ROBIN: 'ROUND_ROBIN',
11 /**
737c6d97 12 * Less used worker selection strategy.
bdaf31cd 13 */
737c6d97 14 LESS_USED: 'LESS_USED',
23ff945a
JB
15 /**
16 * Fair share worker selection strategy.
17 */
18 FAIR_SHARE: 'FAIR_SHARE',
b3432a63
JB
19 /**
20 * Weighted round robin worker selection strategy.
21 */
22 WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN'
bdaf31cd
JB
23} as const)
24
25/**
26 * Worker choice strategy.
27 */
28export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
29
10fcfaf4 30/**
ea7a90d3 31 * Pool tasks usage statistics requirements.
10fcfaf4 32 */
78cea37e 33export interface RequiredStatistics {
10fcfaf4
JB
34 runTime: boolean
35}
36
bdaf31cd
JB
37/**
38 * Worker choice strategy interface.
39 *
38e795c1 40 * @typeParam Worker - Type of worker which manages the strategy.
bdaf31cd 41 */
ea7a90d3 42export interface IWorkerChoiceStrategy<Worker extends IPoolWorker> {
bdaf31cd
JB
43 /**
44 * Is the pool attached to the strategy dynamic?.
45 */
ea7a90d3 46 readonly isDynamicPool: boolean
10fcfaf4 47 /**
ea7a90d3 48 * Required pool tasks usage statistics.
10fcfaf4 49 */
ea7a90d3
JB
50 readonly requiredStatistics: RequiredStatistics
51 /**
a6f7f1b4 52 * Resets strategy internals (counters, statistics, etc.).
ea7a90d3 53 */
78cea37e 54 reset: () => boolean
bdaf31cd 55 /**
bdede008 56 * Chooses a worker in the pool.
bdaf31cd 57 */
78cea37e 58 choose: () => Worker
bdaf31cd 59}