feat: add option to enable worker tasks queue
[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 {
36 medRunTime?: boolean
37}
38
10fcfaf4 39/**
9cd39dd4 40 * Pool worker tasks usage statistics requirements.
10fcfaf4 41 */
78cea37e 42export interface RequiredStatistics {
10fcfaf4 43 runTime: boolean
c6bd2650 44 avgRunTime: boolean
78099a15 45 medRunTime: boolean
10fcfaf4
JB
46}
47
bdaf31cd
JB
48/**
49 * Worker choice strategy interface.
bdaf31cd 50 */
17393ac8 51export interface IWorkerChoiceStrategy {
10fcfaf4 52 /**
f06e48d8 53 * Required tasks usage statistics.
10fcfaf4 54 */
ea7a90d3
JB
55 readonly requiredStatistics: RequiredStatistics
56 /**
a6f7f1b4 57 * Resets strategy internals (counters, statistics, etc.).
ea7a90d3 58 */
78cea37e 59 reset: () => boolean
bdaf31cd 60 /**
f06e48d8 61 * Chooses a worker node in the pool and returns its key.
bdaf31cd 62 */
c923ce56 63 choose: () => number
97a2abc3 64 /**
f06e48d8 65 * Removes a worker node key from strategy internals.
97a2abc3 66 *
f06e48d8 67 * @param workerNodeKey - The worker node key.
97a2abc3 68 */
f06e48d8 69 remove: (workerNodeKey: number) => boolean
bdaf31cd 70}