quickwit_actors/observation.rs
1// Copyright (C) 2021 Quickwit, Inc.
2//
3// Quickwit is offered under the AGPL v3.0 and as commercial software.
4// For commercial licensing, contact us at hello@quickwit.io.
5//
6// AGPL:
7// This program is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Affero General Public License as
9// published by the Free Software Foundation, either version 3 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU Affero General Public License for more details.
16//
17// You should have received a copy of the GNU Affero General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20use std::fmt;
21use std::ops::Deref;
22
23#[derive(Debug)]
24pub struct Observation<ObservableState> {
25 pub obs_type: ObservationType,
26 pub state: ObservableState,
27}
28
29impl<ObservableState> Deref for Observation<ObservableState> {
30 type Target = ObservableState;
31
32 fn deref(&self) -> &Self::Target {
33 &self.state
34 }
35}
36
37// Describes the actual outcome of observation.
38#[derive(Debug, Clone, Copy, Eq, PartialEq)]
39pub enum ObservationType {
40 /// The actor is alive and was able to snapshot its state within `HEARTBEAT`
41 Alive,
42 /// An observation could not be made with HEARTBEAT, because
43 /// the actor had too much work. In that case, in a best effort fashion, the
44 /// last observed state is returned. The actor will still update its state,
45 /// as soon as it has finished processing the current message.
46 Timeout,
47 /// The actor has exited. The post-mortem state is joined.
48 PostMortem,
49}
50
51impl<State: fmt::Debug + PartialEq> PartialEq for Observation<State> {
52 fn eq(&self, other: &Self) -> bool {
53 self.obs_type.eq(&other.obs_type) && self.state.eq(&other.state)
54 }
55}
56
57impl<State: fmt::Debug + PartialEq + Eq> Eq for Observation<State> {}