use std::{ops::Deref, sync::Arc};
use prometheus::Registry;
use crate::services::{consumers::Consumers, handler::Handler, staging::Staging};
#[derive(Clone)]
pub struct SharedState(Arc<State>);
impl SharedState {
pub async fn new() -> anyhow::Result<Self> {
Ok(Self(Arc::new(State::new().await?)))
}
}
impl Deref for SharedState {
type Target = Arc<State>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
pub struct State {
pub staging: Staging,
pub consumers: Consumers,
pub handler: Handler,
pub metrics_registry: Registry,
}
impl State {
pub async fn new() -> anyhow::Result<Self> {
let staging = Staging::new().await?;
let handler = Handler::new(staging.clone());
Ok(Self {
consumers: Consumers::new(),
staging,
handler,
metrics_registry: Registry::new(),
})
}
}