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 | ||
ff733df7 JB |
32 | /** |
33 | * Worker choice strategy options. | |
34 | */ | |
35 | export interface WorkerChoiceStrategyOptions { | |
b0623665 JB |
36 | /** |
37 | * Use tasks median run time instead of average run time. | |
d29bce7c JB |
38 | * |
39 | * @defaultValue false | |
b0623665 | 40 | */ |
ff733df7 JB |
41 | medRunTime?: boolean |
42 | } | |
43 | ||
10fcfaf4 | 44 | /** |
9cd39dd4 | 45 | * Pool worker tasks usage statistics requirements. |
71ebe93b JB |
46 | * |
47 | * @internal | |
10fcfaf4 | 48 | */ |
78cea37e | 49 | export interface RequiredStatistics { |
243a550a JB |
50 | /** |
51 | * Require tasks run time. | |
52 | */ | |
10fcfaf4 | 53 | runTime: boolean |
243a550a JB |
54 | /** |
55 | * Require tasks average run time. | |
56 | */ | |
c6bd2650 | 57 | avgRunTime: boolean |
243a550a JB |
58 | /** |
59 | * Require tasks median run time. | |
60 | */ | |
78099a15 | 61 | medRunTime: boolean |
10fcfaf4 JB |
62 | } |
63 | ||
bdaf31cd JB |
64 | /** |
65 | * Worker choice strategy interface. | |
bdaf31cd | 66 | */ |
17393ac8 | 67 | export interface IWorkerChoiceStrategy { |
10fcfaf4 | 68 | /** |
f06e48d8 | 69 | * Required tasks usage statistics. |
10fcfaf4 | 70 | */ |
ea7a90d3 JB |
71 | readonly requiredStatistics: RequiredStatistics |
72 | /** | |
a6f7f1b4 | 73 | * Resets strategy internals (counters, statistics, etc.). |
ea7a90d3 | 74 | */ |
78cea37e | 75 | reset: () => boolean |
bdaf31cd | 76 | /** |
f06e48d8 | 77 | * Chooses a worker node in the pool and returns its key. |
bdaf31cd | 78 | */ |
c923ce56 | 79 | choose: () => number |
97a2abc3 | 80 | /** |
f06e48d8 | 81 | * Removes a worker node key from strategy internals. |
97a2abc3 | 82 | * |
f06e48d8 | 83 | * @param workerNodeKey - The worker node key. |
97a2abc3 | 84 | */ |
f06e48d8 | 85 | remove: (workerNodeKey: number) => boolean |
a20f0ba5 JB |
86 | /** |
87 | * Sets the worker choice strategy options. | |
88 | * | |
89 | * @param opts - The worker choice strategy options. | |
90 | */ | |
91 | setOptions: (opts: WorkerChoiceStrategyOptions) => void | |
bdaf31cd | 92 | } |