vector_tap/
notification.rs

1#[cfg(feature = "api")]
2use async_graphql::{SimpleObject, Union};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5#[cfg_attr(feature = "api", derive(SimpleObject))]
6/// A component was found that matched the provided pattern
7pub struct Matched {
8    #[cfg_attr(feature = "api", graphql(skip))]
9    message: String,
10    /// Pattern that raised the notification
11    pub pattern: String,
12}
13
14impl Matched {
15    pub fn new(pattern: String) -> Self {
16        Self {
17            message: format!("[tap] Pattern '{pattern}' successfully matched."),
18            pattern,
19        }
20    }
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24#[cfg_attr(feature = "api", derive(SimpleObject))]
25/// There isn't currently a component that matches this pattern
26pub struct NotMatched {
27    #[cfg_attr(feature = "api", graphql(skip))]
28    message: String,
29    /// Pattern that raised the notification
30    pub pattern: String,
31}
32
33impl NotMatched {
34    pub fn new(pattern: String) -> Self {
35        Self {
36            message: format!(
37                "[tap] Pattern '{pattern}' failed to match: will retry on configuration reload."
38            ),
39            pattern,
40        }
41    }
42}
43
44#[derive(Debug, Clone, PartialEq, Eq)]
45#[cfg_attr(feature = "api", derive(SimpleObject))]
46/// The pattern matched source(s) which cannot be tapped for inputs or sink(s)
47/// which cannot be tapped for outputs
48pub struct InvalidMatch {
49    #[cfg_attr(feature = "api", graphql(skip))]
50    message: String,
51    /// Pattern that raised the notification
52    pattern: String,
53    /// Any invalid matches for the pattern
54    invalid_matches: Vec<String>,
55}
56
57impl InvalidMatch {
58    pub fn new(message: String, pattern: String, invalid_matches: Vec<String>) -> Self {
59        Self {
60            message,
61            pattern,
62            invalid_matches,
63        }
64    }
65}
66
67#[derive(Debug, Clone, PartialEq, Eq)]
68#[cfg_attr(feature = "api", derive(Union))]
69/// A specific kind of notification with additional details
70pub enum Notification {
71    Matched(Matched),
72    NotMatched(NotMatched),
73    InvalidMatch(InvalidMatch),
74}
75
76impl Notification {
77    pub fn as_str(&self) -> &str {
78        match self {
79            Notification::Matched(n) => n.message.as_ref(),
80            Notification::NotMatched(n) => n.message.as_ref(),
81            Notification::InvalidMatch(n) => n.message.as_ref(),
82        }
83    }
84}