mirror of
https://github.com/csehviktor/status-monitor.git
synced 2026-04-28 16:27:34 +02:00
cleanup code
This commit is contained in:
+10
-10
@@ -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>>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user