mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-16 22:12:36 -06:00
feat: setup healthcheck route & background task
This commit is contained in:
@@ -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())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user