heartbeat the matrix-accounts snapshot so as_of tracks daemon liveness
This commit is contained in:
parent
f38bc13293
commit
d5202ebf60
2 changed files with 104 additions and 6 deletions
|
|
@ -46,6 +46,12 @@ use accounts::{AccountCfg, Registry};
|
|||
/// `select_all`) rather than `tokio::spawn`/`JoinSet`.
|
||||
type SyncLoop = std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>>>>;
|
||||
|
||||
/// How often the daemon rewrites the accounts snapshot to advance its
|
||||
/// mtime, so the dashboard's `as_of` tracks daemon liveness. 30s keeps
|
||||
/// the staleness window small while the rewrite cost (one tmp + rename of
|
||||
/// a tiny file) is negligible.
|
||||
const ACCOUNTS_HEARTBEAT_SECS: u64 = 30;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
tracing_subscriber::fmt()
|
||||
|
|
@ -116,6 +122,26 @@ async fn main() -> Result<()> {
|
|||
// sync loops so the MCP bridge can connect as soon as the first
|
||||
// claude turn fires.
|
||||
let registry = Arc::new(registry);
|
||||
|
||||
// Heartbeat: periodically rewrite the accounts snapshot so its mtime
|
||||
// advances while the daemon lives. The dashboard derives `as_of` from
|
||||
// the file mtime, so a stalled mtime now means the daemon is down —
|
||||
// which lets the dashboard dim accounts whose snapshot is stale rather
|
||||
// than reporting the boot-time set forever (BE-4 follow-up).
|
||||
let hb_registry = Arc::clone(®istry);
|
||||
tokio::spawn(async move {
|
||||
let mut tick =
|
||||
tokio::time::interval(std::time::Duration::from_secs(ACCOUNTS_HEARTBEAT_SECS));
|
||||
tick.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
|
||||
let path = paths::accounts_file();
|
||||
loop {
|
||||
tick.tick().await;
|
||||
if let Err(e) = hb_registry.heartbeat_snapshot(&path) {
|
||||
tracing::warn!(error = %format!("{e:#}"), "matrix-accounts heartbeat write failed");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let socket_listener = mcp_socket.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = socket::serve(&socket_listener, registry).await {
|
||||
|
|
|
|||
Loading…
Reference in a new issue