Commit | Line | Data |
---|---|---|
bdaf31cd JB |
1 | /** |
2 | * Enumeration of worker choice strategies. | |
3 | */ | |
4 | export const WorkerChoiceStrategies = Object.freeze({ | |
5 | /** | |
6 | * Round robin worker selection strategy. | |
7 | */ | |
8 | ROUND_ROBIN: 'ROUND_ROBIN', | |
9 | /** | |
737c6d97 | 10 | * Less used worker selection strategy. |
bdaf31cd | 11 | */ |
737c6d97 | 12 | LESS_USED: 'LESS_USED', |
168c526f JB |
13 | /** |
14 | * Less busy worker selection strategy. | |
15 | */ | |
16 | LESS_BUSY: 'LESS_BUSY', | |
23ff945a JB |
17 | /** |
18 | * Fair share worker selection strategy. | |
19 | */ | |
20 | FAIR_SHARE: 'FAIR_SHARE', | |
b3432a63 JB |
21 | /** |
22 | * Weighted round robin worker selection strategy. | |
23 | */ | |
24 | WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN' | |
bdaf31cd JB |
25 | } as const) |
26 | ||
27 | /** | |
28 | * Worker choice strategy. | |
29 | */ | |
30 | export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies | |
31 | ||
10fcfaf4 | 32 | /** |
ea7a90d3 | 33 | * Pool tasks usage statistics requirements. |
10fcfaf4 | 34 | */ |
78cea37e | 35 | export interface RequiredStatistics { |
10fcfaf4 JB |
36 | runTime: boolean |
37 | } | |
38 | ||
bdaf31cd JB |
39 | /** |
40 | * Worker choice strategy interface. | |
bdaf31cd | 41 | */ |
c923ce56 | 42 | export interface IWorkerChoiceStrategy { |
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 | /** |
c923ce56 | 56 | * Chooses a worker in the pool and returns its key. |
bdaf31cd | 57 | */ |
c923ce56 | 58 | choose: () => number |
bdaf31cd | 59 | } |