ralph_workflow/json_parser/health/
monitor.rs1pub struct HealthMonitor {
10 health: Cell<ParserHealth>,
11 parser_name: &'static str,
12 threshold_warned: Cell<bool>,
13}
14
15impl HealthMonitor {
16 pub fn new(parser_name: &'static str) -> Self {
18 Self {
19 health: Cell::new(ParserHealth::new()),
20 parser_name,
21 threshold_warned: Cell::new(false),
22 }
23 }
24
25 pub fn record_parsed(&self) {
27 let mut h = self.health.get();
28 h.record_parsed();
29 self.health.set(h);
30 }
31
32 pub fn record_ignored(&self) {
34 let mut h = self.health.get();
35 h.record_ignored();
36 self.health.set(h);
37 }
38
39 pub fn record_unknown_event(&self) {
41 let mut h = self.health.get();
42 h.record_unknown_event();
43 self.health.set(h);
44 }
45
46 pub fn record_parse_error(&self) {
48 let mut h = self.health.get();
49 h.record_parse_error();
50 self.health.set(h);
51 }
52
53 pub fn record_control_event(&self) {
55 let mut h = self.health.get();
56 h.record_control_event();
57 self.health.set(h);
58 }
59
60 pub fn record_partial_event(&self) {
66 let mut h = self.health.get();
67 h.record_partial_event();
68 self.health.set(h);
69 }
70
71 pub fn check_and_warn(&self, colors: Colors) -> Option<String> {
73 if self.threshold_warned.get() {
74 return None;
75 }
76
77 let health = self.health.get();
78 let warning = health.warning(self.parser_name, colors);
79 if warning.is_some() {
80 self.threshold_warned.set(true);
81 }
82 warning
83 }
84}