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