vector_tap/
notification.rs1#[cfg(feature = "api")]
2use async_graphql::{SimpleObject, Union};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5#[cfg_attr(feature = "api", derive(SimpleObject))]
6pub struct Matched {
8 #[cfg_attr(feature = "api", graphql(skip))]
9 message: String,
10 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))]
25pub struct NotMatched {
27 #[cfg_attr(feature = "api", graphql(skip))]
28 message: String,
29 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))]
46pub struct InvalidMatch {
49 #[cfg_attr(feature = "api", graphql(skip))]
50 message: String,
51 pattern: String,
53 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))]
69pub 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}