mirror of
https://github.com/csehviktor/status-monitor.git
synced 2026-04-29 00:27:35 +02:00
formatter + implement status history
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use rumqttd::{local::LinkRx, Broker, Notification};
|
||||
use common::{StatusMessage, MQTT_TOPIC};
|
||||
use common::{MQTT_TOPIC, StatusMessage};
|
||||
use rumqttd::{Broker, Notification, local::LinkRx};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{bridge::ClientManager, storage::StorageRepository};
|
||||
@@ -11,7 +11,11 @@ pub struct MqttSubscriber {
|
||||
}
|
||||
|
||||
impl MqttSubscriber {
|
||||
pub fn new(broker: &Broker, clients: Arc<ClientManager>, storage: Arc<dyn StorageRepository>) -> Self {
|
||||
pub fn new(
|
||||
broker: &Broker,
|
||||
clients: Arc<ClientManager>,
|
||||
storage: Arc<dyn StorageRepository>,
|
||||
) -> Self {
|
||||
let (mut link_tx, link_rx) = broker.link("internal-subscriber").unwrap();
|
||||
link_tx.subscribe(MQTT_TOPIC).unwrap();
|
||||
|
||||
@@ -32,6 +36,10 @@ impl MqttSubscriber {
|
||||
if let Err(e) = self.storage.record_uptime(&payload.agent).await {
|
||||
eprintln!("failed to record uptime for {}: {}", &payload.agent, e);
|
||||
}
|
||||
|
||||
if let Err(e) = self.storage.record_message(&payload).await {
|
||||
eprintln!("failed to record message for {}: {}", &payload.agent, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user