formatter + implement status history

This commit is contained in:
csehviktor
2025-07-15 01:08:51 +02:00
parent 61fb1b1583
commit 6a311246f6
16 changed files with 245 additions and 110 deletions
+1 -1
View File
@@ -1,8 +1,8 @@
use rumqttd::{Broker, Config};
use std::sync::Arc;
use crate::{bridge::ClientManager, storage::StorageRepositoryImpl};
use super::subscriber::MqttSubscriber;
use crate::{bridge::ClientManager, storage::StorageRepositoryImpl};
pub struct MqttBroker {
broker: &'static mut Broker,
+11 -3
View File
@@ -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);
}
}
}