Skip to main content

wowlab_sentinel/scheduler/runtime/
strategy.rs

1use wowlab_common::{RuntimeWorkItem, RuntimeWorkResult};
2
3use super::tournament::TournamentRuntime;
4use crate::{
5    scheduler::{
6        runtime_aggregate::{SingleRuntime, StatWeightsRuntime},
7        runtime_breakdown::RuntimeMemoryBreakdown,
8    },
9    strategy::{FinalOutput, StrategyError},
10};
11
12#[derive(Debug)]
13pub(super) enum RuntimeStrategyState {
14    Tournament(Box<TournamentRuntime>),
15    Single(Box<SingleRuntime>),
16    StatWeights(StatWeightsRuntime),
17}
18
19impl RuntimeStrategyState {
20    pub(super) fn next_work(
21        &mut self,
22        max_items: usize,
23        next_item_id: &mut u64,
24    ) -> Vec<RuntimeWorkItem> {
25        match self {
26            Self::Tournament(t) => t.next_work(max_items, next_item_id),
27            Self::Single(s) => s.next_work(max_items, next_item_id),
28            Self::StatWeights(s) => s.next_work(max_items, next_item_id),
29        }
30    }
31
32    pub(super) fn ingest(&mut self, results: &[RuntimeWorkResult]) -> Result<(), StrategyError> {
33        match self {
34            Self::Tournament(t) => {
35                t.ingest(results);
36
37                Ok(())
38            }
39            Self::Single(s) => s.ingest(results),
40            Self::StatWeights(s) => s.ingest(results),
41        }
42    }
43
44    pub(super) fn is_complete(&self) -> bool {
45        match self {
46            Self::Tournament(t) => t.is_complete(),
47            Self::Single(s) => s.is_complete(),
48            Self::StatWeights(s) => s.is_complete(),
49        }
50    }
51
52    pub(super) fn has_pending(&self) -> bool {
53        match self {
54            Self::Tournament(t) => !t.is_complete(),
55            Self::Single(s) => s.has_pending(),
56            Self::StatWeights(s) => s.has_pending(),
57        }
58    }
59
60    pub(super) fn peek_next_work_shape(&self) -> (u32, bool) {
61        match self {
62            Self::Tournament(t) => t.peek_next_work_shape(),
63            Self::Single(s) => s.peek_shape(),
64            Self::StatWeights(s) => s.peek_shape(),
65        }
66    }
67
68    pub(super) fn finalize(&self) -> Result<FinalOutput, StrategyError> {
69        match self {
70            Self::Tournament(t) => t.finalize(),
71            Self::Single(s) => s.finalize(),
72            Self::StatWeights(s) => s.finalize(),
73        }
74    }
75
76    pub(super) fn memory_breakdown(&self) -> RuntimeMemoryBreakdown {
77        match self {
78            Self::Tournament(t) => t.memory_breakdown(),
79            _ => RuntimeMemoryBreakdown::default(),
80        }
81    }
82}