ddns_core/
status.rs

1//! Runtime status shared between HTTP dashboard and scheduler.
2
3use chrono::{DateTime, Utc};
4use parking_lot::RwLock;
5use serde::Serialize;
6use std::{collections::HashMap, sync::Arc};
7use tokio::sync::broadcast;
8
9#[derive(Clone, Serialize, Default)]
10pub struct ProviderStat {
11    pub last_ok: Option<DateTime<Utc>>,
12    pub last_err: Option<String>,
13}
14
15#[derive(Clone, Serialize, Default)]
16pub struct AppStatus {
17    pub now: DateTime<Utc>,
18    pub next_tick: Option<DateTime<Utc>>,
19    pub current_ip: Option<String>,
20    pub providers: HashMap<String, ProviderStat>,
21}
22
23/// Wrapped by `Arc<RwLock<_>>`
24pub type SharedStatus = Arc<RwLock<AppStatus>>;
25
26/// Events sent to the front-end via server-sent events
27#[derive(Clone, Serialize)]
28#[serde(tag = "type", content = "payload")]
29pub enum Event {
30    #[serde(rename = "status")]
31    Status(AppStatus),
32    #[serde(rename = "log")]
33    Log(String),
34}
35
36/// Recommended buffer size is 1024; older events are dropped when full.
37pub type EventBus = broadcast::Sender<Event>;