bestool_alertd/context.rs
1use std::sync::Arc;
2
3use tokio::sync::watch;
4
5use crate::canopy::CanopyClient;
6
7/// Shared resources the daemon holds for the lifetime of the process and hands
8/// to background tasks and HTTP endpoints.
9#[derive(Debug, Clone)]
10pub struct InternalContext {
11 /// `None` on hosts with no Tamanu deployment (and therefore no database).
12 pub pg_pool: Option<bestool_postgres::pool::PgPool>,
13 pub http_client: reqwest::Client,
14 pub canopy_client: Option<Arc<CanopyClient>>,
15 /// Bumped on each reload request (SIGHUP/SIGUSR1); tasks watch it to refresh
16 /// their state without a restart.
17 pub reload: watch::Receiver<u64>,
18 /// Handle to ask the daemon to restart itself. `None` in detached test
19 /// contexts. Used by the self-update task after it replaces the binary.
20 pub restart: Option<crate::daemon::RestartTrigger>,
21}