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:
38
src/app/service.rs
Normal file
38
src/app/service.rs
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user