huskies: merge 1156 story Periodic liveness tick so runtime freezes have a precise timestamp

This commit is contained in:
dave
2026-05-20 01:18:59 +00:00
parent 7be3bf1dbf
commit 2fb935e726
4 changed files with 43 additions and 0 deletions
+23
View File
@@ -226,6 +226,29 @@ pub(crate) fn spawn_tick_loop(
});
}
/// Spawn a permanent background task that emits a liveness heartbeat log line
/// every `interval_secs` seconds on the main tokio runtime.
///
/// Running on the main runtime (not `spawn_blocking`) means the heartbeat stops
/// the moment the runtime freezes, giving an exact timestamp of the freeze from
/// the last `[liveness]` line in the logs.
pub(crate) fn spawn_liveness_tick(interval_secs: u64) {
let interval_secs = interval_secs.max(1);
crate::slog!("[liveness] liveness tick started; cadence={interval_secs}s");
tokio::spawn(async move {
let duration = std::time::Duration::from_secs(interval_secs);
let mut ticker = tokio::time::interval(duration);
loop {
ticker.tick().await;
let ts = std::time::UNIX_EPOCH
.elapsed()
.unwrap_or_default()
.as_secs();
crate::slog!("[liveness] tokio runtime alive ts={ts}");
}
});
}
/// Fire any due generic scheduled timers and re-arm recurring ones.
///
/// Called every second from the unified tick loop. Catch-up semantics: timers