refactor(notify): rename NotifyEvent to NotificationEvent
CI / Check & Lint (push) Failing after 19m30s
CI / Check & Lint (push) Failing after 19m30s
This commit is contained in:
+117
@@ -0,0 +1,117 @@
|
|||||||
|
diff --git a/workshop-baker/src/notify.rs b/workshop-baker/src/notify.rs
|
||||||
|
index 75bce82..ad56c66 100644
|
||||||
|
--- a/workshop-baker/src/notify.rs
|
||||||
|
+++ b/workshop-baker/src/notify.rs
|
||||||
|
@@ -3,15 +3,15 @@ use crate::finalize::FinalizeConfig;
|
||||||
|
use crate::finalize::parse;
|
||||||
|
use crate::finalize::plugin;
|
||||||
|
use crate::finalize::plugin::fetch;
|
||||||
|
-use crate::notify::types::BundledNotifyEvent;
|
||||||
|
+use crate::notify::types::BundledNotificationEvent;
|
||||||
|
use crate::notify::types::NOTIFY_TEMPORARY_DELAY_FACTOR;
|
||||||
|
use crate::notify::types::NOTIFY_TEMPORARY_DELAY_TIME;
|
||||||
|
use crate::notify::types::NOTIFY_TEMPORARY_MAX_TIME;
|
||||||
|
use crate::notify::types::NotificationRulesMap;
|
||||||
|
-use crate::notify::types::NotifyEvent;
|
||||||
|
-use crate::notify::types::NotifyEventReceiver;
|
||||||
|
-use crate::notify::types::NotifyEventSender;
|
||||||
|
-use crate::notify::types::NotifyPluginMap;
|
||||||
|
+use crate::notify::types::NotificationEvent;
|
||||||
|
+use crate::notify::types::NotificationEventReceiver;
|
||||||
|
+use crate::notify::types::NotificationEventSender;
|
||||||
|
+use crate::notify::types::NotificationPluginMap;
|
||||||
|
use crate::{EventSender, ExecutionContext};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::path::Path;
|
||||||
|
@@ -46,8 +46,8 @@ pub async fn notify(
|
||||||
|
finalize_path: &Path,
|
||||||
|
ctx: &mut ExecutionContext,
|
||||||
|
event_tx: EventSender,
|
||||||
|
- notifyevent_rx: &mut NotifyEventReceiver,
|
||||||
|
- notifyevent_tx: NotifyEventSender,
|
||||||
|
+ notifyevent_rx: &mut NotificationEventReceiver,
|
||||||
|
+ notifyevent_tx: NotificationEventSender,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let mut finalize = parse(finalize_path)?;
|
||||||
|
validate(&finalize)?;
|
||||||
|
@@ -114,10 +114,11 @@ pub async fn notify(
|
||||||
|
}
|
||||||
|
|
||||||
|
fn notification_handler(
|
||||||
|
- plugins: &NotifyPluginMap,
|
||||||
|
+ plugins: &NotificationPluginMap,
|
||||||
|
config: &NotificationRulesMap,
|
||||||
|
- event: &BundledNotifyEvent,
|
||||||
|
+ event: &BundledNotificationEvent,
|
||||||
|
) -> Result<(), NotifyError> {
|
||||||
|
+
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -132,7 +133,7 @@ fn wait_time(group_period: u32, group_watermark: u32, count: u32) -> f32 {
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate p^(m-l)*t as notification delay
|
||||||
|
-fn notify_delay(event: &NotifyEvent) -> std::time::Duration {
|
||||||
|
+fn notify_delay(event: &NotificationEvent) -> std::time::Duration {
|
||||||
|
let exponent = (event.max_lives - event.lives) as i32;
|
||||||
|
if exponent < 0 {
|
||||||
|
log::warn!(
|
||||||
|
diff --git a/workshop-baker/src/notify/types.rs b/workshop-baker/src/notify/types.rs
|
||||||
|
index b852dfb..d6ccfb7 100644
|
||||||
|
--- a/workshop-baker/src/notify/types.rs
|
||||||
|
+++ b/workshop-baker/src/notify/types.rs
|
||||||
|
@@ -39,13 +39,13 @@ pub struct NotificationRule{
|
||||||
|
pub type Priority = u32;
|
||||||
|
pub type Method = String;
|
||||||
|
pub type NotificationRulesMap = HashMap<Priority, HashMap<Method, Vec<NotificationRule>>>;
|
||||||
|
-pub type BundledNotifyEvent = Vec<NotifyEvent>;
|
||||||
|
-pub type NotifyEventReceiver = tokio::sync::mpsc::Receiver<BundledNotifyEvent>;
|
||||||
|
-pub type NotifyEventSender = tokio::sync::mpsc::Sender<NotifyEvent>;
|
||||||
|
-pub type NotifyPluginMap = HashMap<String, FinalizePlugin>;
|
||||||
|
+pub type BundledNotificationEvent = Vec<NotificationEvent>;
|
||||||
|
+pub type NotificationEventReceiver = tokio::sync::mpsc::Receiver<BundledNotificationEvent>;
|
||||||
|
+pub type NotificationEventSender = tokio::sync::mpsc::Sender<NotificationEvent>;
|
||||||
|
+pub type NotificationPluginMap = HashMap<String, FinalizePlugin>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
-pub struct NotifyEvent {
|
||||||
|
+pub struct NotificationEvent {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub stage: StagePhase,
|
||||||
|
pub substage: String,
|
||||||
|
@@ -58,21 +58,21 @@ pub struct NotifyEvent {
|
||||||
|
pub target: HashSet<String>, // Target audience
|
||||||
|
}
|
||||||
|
|
||||||
|
-impl Hash for NotifyEvent {
|
||||||
|
+impl Hash for NotificationEvent {
|
||||||
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
|
self.id.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-impl PartialEq for NotifyEvent {
|
||||||
|
+impl PartialEq for NotificationEvent {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.id == other.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-impl Eq for NotifyEvent {}
|
||||||
|
+impl Eq for NotificationEvent {}
|
||||||
|
|
||||||
|
-impl PartialOrd for NotifyEvent {
|
||||||
|
+impl PartialOrd for NotificationEvent {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
Some(
|
||||||
|
self.effective_priority
|
||||||
|
@@ -83,7 +83,7 @@ impl PartialOrd for NotifyEvent {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-impl Ord for NotifyEvent {
|
||||||
|
+impl Ord for NotificationEvent {
|
||||||
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
|
self.partial_cmp(other).unwrap()
|
||||||
|
}
|
||||||
@@ -3,15 +3,15 @@ use crate::finalize::FinalizeConfig;
|
|||||||
use crate::finalize::parse;
|
use crate::finalize::parse;
|
||||||
use crate::finalize::plugin;
|
use crate::finalize::plugin;
|
||||||
use crate::finalize::plugin::fetch;
|
use crate::finalize::plugin::fetch;
|
||||||
use crate::notify::types::BundledNotifyEvent;
|
use crate::notify::types::BundledNotificationEvent;
|
||||||
use crate::notify::types::NOTIFY_TEMPORARY_DELAY_FACTOR;
|
use crate::notify::types::NOTIFY_TEMPORARY_DELAY_FACTOR;
|
||||||
use crate::notify::types::NOTIFY_TEMPORARY_DELAY_TIME;
|
use crate::notify::types::NOTIFY_TEMPORARY_DELAY_TIME;
|
||||||
use crate::notify::types::NOTIFY_TEMPORARY_MAX_TIME;
|
use crate::notify::types::NOTIFY_TEMPORARY_MAX_TIME;
|
||||||
use crate::notify::types::NotificationRulesMap;
|
use crate::notify::types::NotificationRulesMap;
|
||||||
use crate::notify::types::NotifyEvent;
|
use crate::notify::types::NotificationEvent;
|
||||||
use crate::notify::types::NotifyEventReceiver;
|
use crate::notify::types::NotificationEventReceiver;
|
||||||
use crate::notify::types::NotifyEventSender;
|
use crate::notify::types::NotificationEventSender;
|
||||||
use crate::notify::types::NotifyPluginMap;
|
use crate::notify::types::NotificationPluginMap;
|
||||||
use crate::{EventSender, ExecutionContext};
|
use crate::{EventSender, ExecutionContext};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@@ -46,8 +46,8 @@ pub async fn notify(
|
|||||||
finalize_path: &Path,
|
finalize_path: &Path,
|
||||||
ctx: &mut ExecutionContext,
|
ctx: &mut ExecutionContext,
|
||||||
event_tx: EventSender,
|
event_tx: EventSender,
|
||||||
notifyevent_rx: &mut NotifyEventReceiver,
|
notifyevent_rx: &mut NotificationEventReceiver,
|
||||||
notifyevent_tx: NotifyEventSender,
|
notifyevent_tx: NotificationEventSender,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut finalize = parse(finalize_path)?;
|
let mut finalize = parse(finalize_path)?;
|
||||||
validate(&finalize)?;
|
validate(&finalize)?;
|
||||||
@@ -114,10 +114,11 @@ pub async fn notify(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn notification_handler(
|
fn notification_handler(
|
||||||
plugins: &NotifyPluginMap,
|
plugins: &NotificationPluginMap,
|
||||||
config: &NotificationRulesMap,
|
config: &NotificationRulesMap,
|
||||||
event: &BundledNotifyEvent,
|
event: &BundledNotificationEvent,
|
||||||
) -> Result<(), NotifyError> {
|
) -> Result<(), NotifyError> {
|
||||||
|
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +133,7 @@ fn wait_time(group_period: u32, group_watermark: u32, count: u32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculate p^(m-l)*t as notification delay
|
// calculate p^(m-l)*t as notification delay
|
||||||
fn notify_delay(event: &NotifyEvent) -> std::time::Duration {
|
fn notify_delay(event: &NotificationEvent) -> std::time::Duration {
|
||||||
let exponent = (event.max_lives - event.lives) as i32;
|
let exponent = (event.max_lives - event.lives) as i32;
|
||||||
if exponent < 0 {
|
if exponent < 0 {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ pub struct NotificationRule{
|
|||||||
pub type Priority = u32;
|
pub type Priority = u32;
|
||||||
pub type Method = String;
|
pub type Method = String;
|
||||||
pub type NotificationRulesMap = HashMap<Priority, HashMap<Method, Vec<NotificationRule>>>;
|
pub type NotificationRulesMap = HashMap<Priority, HashMap<Method, Vec<NotificationRule>>>;
|
||||||
pub type BundledNotifyEvent = Vec<NotifyEvent>;
|
pub type BundledNotificationEvent = Vec<NotificationEvent>;
|
||||||
pub type NotifyEventReceiver = tokio::sync::mpsc::Receiver<BundledNotifyEvent>;
|
pub type NotificationEventReceiver = tokio::sync::mpsc::Receiver<BundledNotificationEvent>;
|
||||||
pub type NotifyEventSender = tokio::sync::mpsc::Sender<NotifyEvent>;
|
pub type NotificationEventSender = tokio::sync::mpsc::Sender<NotificationEvent>;
|
||||||
pub type NotifyPluginMap = HashMap<String, FinalizePlugin>;
|
pub type NotificationPluginMap = HashMap<String, FinalizePlugin>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct NotifyEvent {
|
pub struct NotificationEvent {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub stage: StagePhase,
|
pub stage: StagePhase,
|
||||||
pub substage: String,
|
pub substage: String,
|
||||||
@@ -58,21 +58,21 @@ pub struct NotifyEvent {
|
|||||||
pub target: HashSet<String>, // Target audience
|
pub target: HashSet<String>, // Target audience
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash for NotifyEvent {
|
impl Hash for NotificationEvent {
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
self.id.hash(state);
|
self.id.hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for NotifyEvent {
|
impl PartialEq for NotificationEvent {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.id == other.id
|
self.id == other.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for NotifyEvent {}
|
impl Eq for NotificationEvent {}
|
||||||
|
|
||||||
impl PartialOrd for NotifyEvent {
|
impl PartialOrd for NotificationEvent {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
Some(
|
Some(
|
||||||
self.effective_priority
|
self.effective_priority
|
||||||
@@ -83,7 +83,7 @@ impl PartialOrd for NotifyEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ord for NotifyEvent {
|
impl Ord for NotificationEvent {
|
||||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
self.partial_cmp(other).unwrap()
|
self.partial_cmp(other).unwrap()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user