refactor(app): implement ports & adapters
* also move alertFormatter into internal actor
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
use discord_client::DiscordNotifier;
|
||||
use system_monitor::{SystemMonitor, alert_formatter::AlertFormatter};
|
||||
use crate::app::ports::driven::{
|
||||
ForFormattingMessage, ForMonitoringSystem, ForSendingNotification,
|
||||
};
|
||||
|
||||
pub struct Service {
|
||||
notifier: DiscordNotifier,
|
||||
monitor: SystemMonitor,
|
||||
formatter: AlertFormatter,
|
||||
notifier: Box<dyn ForSendingNotification>,
|
||||
monitor: Box<dyn ForMonitoringSystem>,
|
||||
formatter: Box<dyn ForFormattingMessage>,
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
notifier: DiscordNotifier,
|
||||
monitor: SystemMonitor,
|
||||
formatter: AlertFormatter,
|
||||
notifier: Box<dyn ForSendingNotification>,
|
||||
monitor: Box<dyn ForMonitoringSystem>,
|
||||
formatter: Box<dyn ForFormattingMessage>,
|
||||
) -> Service {
|
||||
Service {
|
||||
notifier,
|
||||
@@ -23,14 +25,14 @@ impl Service {
|
||||
// Check for threshold violations and send alerts
|
||||
let violations = self.monitor.check_thresholds();
|
||||
for violation in violations {
|
||||
let message = self.formatter.format_violation(&violation);
|
||||
let message = self.formatter.format_violation(violation);
|
||||
self.notifier
|
||||
.send_notification(&message)
|
||||
.expect("Failed to send notification");
|
||||
}
|
||||
|
||||
// Send a final notification with all system information
|
||||
let summary = self.formatter.format_summary(&self.monitor);
|
||||
let summary = self.formatter.format_summary(&self.monitor.get_metrics());
|
||||
self.notifier
|
||||
.send_notification(&summary)
|
||||
.expect("Failed to send final notification");
|
||||
|
||||
Reference in New Issue
Block a user