chiark / gitweb /
report, plan
[hippotat.git] / src / reporter.rs
1 // Copyright 2021 Ian Jackson and contributors to Hippotat
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 // There is NO WARRANTY.
4
5 use crate::prelude::*;
6
7 pub struct Reporter<'r> {
8   ic: &'r InstanceConfig,
9 }
10
11 // Reporting strategy
12 //   - report all errors
13 //   - report first success after a period of lack of messages
14 //   - if error, report last success
15
16 impl<'r> Reporter<'r> {
17   pub fn new(ic: &'r InstanceConfig) -> Self { Reporter {
18     ic
19   } }
20   
21   pub fn success(&mut self) {
22     info!("{}: success", self.ic); // xxx
23   }
24   pub fn filter<T>(&mut self, req_num: Option<ReqNum>, r: Result<T,AE>)
25                    -> Option<T> {
26     match r {
27       Ok(t) => {
28         // xxx something something success
29         Some(t)
30       },
31       Err(e) => {
32         // xxx something something error
33         if let Some(req_num) = req_num {
34           warn!("{} #{}: {:?}", self.ic, req_num, e);
35         } else {
36           warn!("{}: {:?}", self.ic, e);
37         }
38         None
39       },
40     }
41   }
42 }