refactor: move business logic into app

* also move all at directory root crate

* all actors are into lib directory

* formatter is into system_monitor now
This commit is contained in:
2025-08-09 13:52:38 +02:00
parent 3bb8f39e34
commit 985ee54669
15 changed files with 67 additions and 68 deletions

38
src/app/service.rs Normal file
View File

@@ -0,0 +1,38 @@
use discord_client::DiscordNotifier;
use system_monitor::{SystemMonitor, alert_formatter::AlertFormatter};
pub struct Service {
notifier: DiscordNotifier,
monitor: SystemMonitor,
formatter: AlertFormatter,
}
pub fn new(
notifier: DiscordNotifier,
monitor: SystemMonitor,
formatter: AlertFormatter,
) -> Service {
Service {
notifier,
monitor,
formatter,
}
}
impl Service {
pub fn run(&self) {
// Check for threshold violations and send alerts
let violations = self.monitor.check_thresholds();
for violation in violations {
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);
self.notifier
.send_notification(&summary)
.expect("Failed to send final notification");
}
}