-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lee Benson <lee@leebenson.com>
- Loading branch information
Showing
7 changed files
with
111 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use async_graphql::Enum; | ||
|
||
#[derive(Enum, Copy, Clone, PartialEq, Eq)] | ||
/// Encoding format for the event | ||
pub enum EventEncodingType { | ||
Json, | ||
Yaml, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use async_graphql::{Enum, SimpleObject}; | ||
|
||
#[derive(Enum, Debug, Copy, Clone, PartialEq, Eq)] | ||
/// Event notification type | ||
pub enum EventNotificationType { | ||
/// A component was found that matched the provided pattern | ||
Matched, | ||
/// There isn't currently a component that matches this pattern | ||
NotMatched, | ||
} | ||
|
||
#[derive(Debug, SimpleObject)] | ||
/// A notification regarding events observation | ||
pub struct EventNotification { | ||
/// Name of the component associated with the notification | ||
component_name: String, | ||
|
||
/// Event notification type | ||
notification: EventNotificationType, | ||
} | ||
|
||
impl EventNotification { | ||
pub fn new(component_name: &str, notification: EventNotificationType) -> Self { | ||
Self { | ||
component_name: component_name.to_string(), | ||
notification, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use super::{ | ||
log::Log, | ||
notification::{EventNotification, EventNotificationType}, | ||
}; | ||
use crate::api::tap::{TapNotification, TapPayload}; | ||
|
||
use async_graphql::Union; | ||
|
||
#[derive(Union, Debug)] | ||
/// An event or a notification | ||
pub enum OutputEventsPayload { | ||
/// Log event | ||
Log(Log), | ||
|
||
// Notification | ||
Notification(EventNotification), | ||
} | ||
|
||
/// Convert an `api::TapPayload` to the equivalent GraphQL type. | ||
impl From<TapPayload> for OutputEventsPayload { | ||
fn from(t: TapPayload) -> Self { | ||
match t { | ||
TapPayload::Log(name, ev) => Self::Log(Log::new(&name, ev)), | ||
TapPayload::Notification(name, n) => match n { | ||
TapNotification::Matched => Self::Notification(EventNotification::new( | ||
&name, | ||
EventNotificationType::Matched, | ||
)), | ||
TapNotification::NotMatched => Self::Notification(EventNotification::new( | ||
&name, | ||
EventNotificationType::NotMatched, | ||
)), | ||
}, | ||
_ => unreachable!("TODO: implement metrics"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters