bestool_alertd/http_server/state.rs
1use std::{collections::HashMap, sync::Arc, time::Duration};
2
3use jiff::Timestamp;
4
5use crate::{context::InternalContext, daemon::DaemonControl, tasks::TaskEndpointHandler};
6
7#[derive(Clone)]
8pub struct ServerState {
9 pub started_at: Timestamp,
10 pub pid: u32,
11 /// Version of the running `bestool` binary (not this crate's version), so
12 /// `/status` reports what self-update targets and operators recognise.
13 pub binary_version: String,
14 pub internal_context: Arc<InternalContext>,
15 pub watchdog_timeout: Option<Duration>,
16 /// Endpoint handlers exposed by registered background tasks. Keyed by
17 /// `(task_name, endpoint_name)` so the `/tasks/:task/:endpoint` route can
18 /// dispatch in O(1) without walking the task registry per request.
19 pub task_endpoints: Arc<HashMap<(String, String), TaskEndpointHandler>>,
20 /// Drives the daemon's `/reload` and `/restart` control endpoints.
21 pub control: DaemonControl,
22 /// Backup run registry, when backups are compiled in; lets `/status` list
23 /// in-flight runs.
24 pub backups: Option<Arc<crate::BackupRegistry>>,
25 /// Handle to the doctor task's latest sweep, when a doctor task is
26 /// registered; feeds per-check stats and the status census to `/metrics`.
27 pub metrics: Option<crate::doctor::DoctorMetricsHandle>,
28}