Commit | Line | Data |
---|---|---|
ea7a90d3 | 1 | import type { IPoolWorker } from '../pool-worker' |
bdaf31cd JB |
2 | |
3 | /** | |
4 | * Enumeration of worker choice strategies. | |
5 | */ | |
6 | export 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', |
168c526f JB |
15 | /** |
16 | * Less busy worker selection strategy. | |
17 | */ | |
18 | LESS_BUSY: 'LESS_BUSY', | |
23ff945a JB |
19 | /** |
20 | * Fair share worker selection strategy. | |
21 | */ | |
22 | FAIR_SHARE: 'FAIR_SHARE', | |
b3432a63 JB |
23 | /** |
24 | * Weighted round robin worker selection strategy. | |
25 | */ | |
26 | WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN' | |
bdaf31cd JB |
27 | } as const) |
28 | ||
29 | /** | |
30 | * Worker choice strategy. | |
31 | */ | |
32 | export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies | |
33 | ||
10fcfaf4 | 34 | /** |
ea7a90d3 | 35 | * Pool tasks usage statistics requirements. |
10fcfaf4 | 36 | */ |
78cea37e | 37 | export interface RequiredStatistics { |
10fcfaf4 JB |
38 | runTime: boolean |
39 | } | |
40 | ||
bdaf31cd JB |
41 | /** |
42 | * Worker choice strategy interface. | |
43 | * | |
38e795c1 | 44 | * @typeParam Worker - Type of worker which manages the strategy. |
bdaf31cd | 45 | */ |
ea7a90d3 | 46 | export interface IWorkerChoiceStrategy<Worker extends IPoolWorker> { |
bdaf31cd JB |
47 | /** |
48 | * Is the pool attached to the strategy dynamic?. | |
49 | */ | |
ea7a90d3 | 50 | readonly isDynamicPool: boolean |
10fcfaf4 | 51 | /** |
ea7a90d3 | 52 | * Required pool tasks usage statistics. |
10fcfaf4 | 53 | */ |
ea7a90d3 JB |
54 | readonly requiredStatistics: RequiredStatistics |
55 | /** | |
a6f7f1b4 | 56 | * Resets strategy internals (counters, statistics, etc.). |
ea7a90d3 | 57 | */ |
78cea37e | 58 | reset: () => boolean |
bdaf31cd | 59 | /** |
bdede008 | 60 | * Chooses a worker in the pool. |
bdaf31cd | 61 | */ |
78cea37e | 62 | choose: () => Worker |
bdaf31cd | 63 | } |