summaryrefslogtreecommitdiff
path: root/src/boot/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot/handlers')
-rw-r--r--src/boot/handlers/boot/mod.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/boot/handlers/boot/mod.rs b/src/boot/handlers/boot/mod.rs
index 010f57b..49691f7 100644
--- a/src/boot/handlers/boot/mod.rs
+++ b/src/boot/handlers/boot/mod.rs
@@ -1,17 +1,26 @@
+use std::time::Duration;
+
use axum::{
extract::{Json, State},
response::{self, IntoResponse},
};
+use serde::Serialize;
-use crate::{app::App, boot::Snapshot, error::Internal, token::extract::Identity, user::User};
+use crate::{
+ app::App, boot::Snapshot, error::Internal, event::Heartbeat, token::extract::Identity,
+ user::User,
+};
#[cfg(test)]
mod test;
pub async fn handler(State(app): State<App>, identity: Identity) -> Result<Response, Internal> {
let snapshot = app.boot().snapshot().await?;
+ let heartbeat = Heartbeat::TIMEOUT;
+
Ok(Response {
user: identity.user,
+ heartbeat,
snapshot,
})
}
@@ -19,6 +28,8 @@ pub async fn handler(State(app): State<App>, identity: Identity) -> Result<Respo
#[derive(serde::Serialize)]
pub struct Response {
pub user: User,
+ #[serde(serialize_with = "as_seconds")]
+ pub heartbeat: Duration,
#[serde(flatten)]
pub snapshot: Snapshot,
}
@@ -28,3 +39,10 @@ impl IntoResponse for Response {
Json(self).into_response()
}
}
+
+fn as_seconds<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
+where
+ S: serde::Serializer,
+{
+ duration.as_secs().serialize(serializer)
+}