feat: setup healthcheck route & background task

This commit is contained in:
Ryan Walters
2025-09-17 12:32:52 -05:00
parent e02c2286bb
commit 916428fe76
4 changed files with 87 additions and 3 deletions

View File

@@ -1,10 +1,38 @@
use dashmap::DashMap;
use jsonwebtoken::{DecodingKey, EncodingKey};
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::data::pool::PgPool;
use crate::{auth::AuthRegistry, config::Config};
#[derive(Debug, Clone)]
pub struct Health {
migrations: bool,
database: bool,
}
impl Health {
pub fn new() -> Self {
Self {
migrations: false,
database: false,
}
}
pub fn ok(&self) -> bool {
self.migrations && self.database
}
pub fn set_migrations(&mut self, done: bool) {
self.migrations = done;
}
pub fn set_database(&mut self, ok: bool) {
self.database = ok;
}
}
#[derive(Clone)]
pub struct AppState {
pub config: Arc<Config>,
@@ -13,6 +41,7 @@ pub struct AppState {
pub jwt_encoding_key: Arc<EncodingKey>,
pub jwt_decoding_key: Arc<DecodingKey>,
pub db: Arc<PgPool>,
pub health: Arc<RwLock<Health>>,
}
impl AppState {
@@ -26,6 +55,7 @@ impl AppState {
jwt_encoding_key: Arc::new(EncodingKey::from_secret(jwt_secret.as_bytes())),
jwt_decoding_key: Arc::new(DecodingKey::from_secret(jwt_secret.as_bytes())),
db: Arc::new(db),
health: Arc::new(RwLock::new(Health::new())),
}
}
}