cleanup code

This commit is contained in:
csehviktor
2025-07-08 14:48:22 +02:00
parent cf92638739
commit 566b56962f
4 changed files with 20 additions and 21 deletions
+10 -10
View File
@@ -10,14 +10,21 @@ pub mod memory;
pub mod sqlite;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UptimeModel {
pub struct UptimeStorageModel {
pub id: String,
pub first_seen: DateTime<Utc>,
pub last_seen: DateTime<Utc>,
pub message_count: u64,
}
impl Into<UptimeMessage> for UptimeModel {
#[derive(Debug, Serialize, Deserialize)]
pub struct UptimeMessage {
pub agent: String,
pub uptime: f64,
pub last_seen: DateTime<Utc>,
}
impl Into<UptimeMessage> for UptimeStorageModel {
fn into(self) -> UptimeMessage {
let duration = Utc::now().signed_duration_since(self.first_seen);
let expected_messages = duration.num_seconds() as f64 / MQTT_SEND_INTERVAL as f64;
@@ -32,16 +39,9 @@ impl Into<UptimeMessage> for UptimeModel {
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UptimeMessage {
pub agent: String,
pub uptime: f64,
pub last_seen: DateTime<Utc>,
}
#[async_trait]
pub trait StorageRepository: Send + Sync {
async fn record_message(&self, agent: &str) -> anyhow::Result<()>;
async fn record_uptime(&self, agent: &str) -> anyhow::Result<()>;
async fn get_agents(&self) -> anyhow::Result<Vec<UptimeMessage>>;
}