P0: config, DTOs, source traits, fakes, error, state and module stubs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aa9b0da962
commit
1802f97d94
22 files changed
+1736
No files matched your search
@@ -0,0 +1,38 @@
|
||||
//! Shared application state handed to every surface.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use sqlx::SqlitePool;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::sources::{DockerSource, JournalSource, SystemdSource};
|
||||
|
||||
/// Cheap to clone. Every stream and background task must select on
|
||||
/// `shutdown` so graceful shutdown cannot hang on open SSE connections.
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub config: Arc<Config>,
|
||||
pub systemd: Arc<dyn SystemdSource>,
|
||||
pub journal: Arc<dyn JournalSource>,
|
||||
pub docker: Arc<dyn DockerSource>,
|
||||
/// `None` when auth is disabled.
|
||||
pub db: Option<SqlitePool>,
|
||||
pub shutdown: CancellationToken,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
/// State backed by the real sources. Source constructors are lazy and
|
||||
/// never fail, so a missing Docker socket does not prevent startup.
|
||||
pub fn live(config: Config, db: Option<SqlitePool>, shutdown: CancellationToken) -> Self {
|
||||
use crate::sources::{docker::BollardDocker, journal::SdJournal, systemd::DbusSystemd};
|
||||
Self {
|
||||
systemd: Arc::new(DbusSystemd::new(&config, shutdown.clone())),
|
||||
journal: Arc::new(SdJournal::new(&config, shutdown.clone())),
|
||||
docker: Arc::new(BollardDocker::new(&config, shutdown.clone())),
|
||||
config: Arc::new(config),
|
||||
db,
|
||||
shutdown,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user