You've already forked AstralRinth
forked from didirus/AstralRinth
Added monitoring, limited concurent connections (#245)
* reduced the default, and added environment override. * Using parse is more stable and doesn't fail CI this time :P * Added support for monitoring This support is currently basic, but it can be improved later down the road. * Forgot scheduler file * Added health check * Cargo fix * Update cargo.lock to avoid action fails. Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
31
src/routes/health.rs
Normal file
31
src/routes/health.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use actix_web::{get, HttpResponse};
|
||||
use serde_json::json;
|
||||
use crate::health::status::test_database;
|
||||
use actix_web::web::Data;
|
||||
use sqlx::PgPool;
|
||||
use crate::health::SEARCH_READY;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
#[get("/health")]
|
||||
pub async fn health_get(client: Data<PgPool>) -> HttpResponse {
|
||||
// Check database connection:
|
||||
let result = test_database(client).await;
|
||||
if result.is_err() {
|
||||
let data = json!({
|
||||
"ready": false,
|
||||
"reason": "Database connection error"
|
||||
});
|
||||
return HttpResponse::InternalServerError().json(data)
|
||||
}
|
||||
if !SEARCH_READY.load(Ordering::Acquire) {
|
||||
let data = json!({
|
||||
"ready": false,
|
||||
"reason": "Indexing is not finished"
|
||||
});
|
||||
return HttpResponse::InternalServerError().json(data)
|
||||
}
|
||||
HttpResponse::Ok().json(json!({
|
||||
"ready": true,
|
||||
"reason": "Everything is OK"
|
||||
}))
|
||||
}
|
||||
@@ -18,11 +18,13 @@ mod users;
|
||||
mod version_creation;
|
||||
mod version_file;
|
||||
mod versions;
|
||||
mod health;
|
||||
|
||||
pub use auth::config as auth_config;
|
||||
pub use tags::config as tags_config;
|
||||
|
||||
pub use self::index::index_get;
|
||||
pub use self::health::health_get;
|
||||
pub use self::not_found::not_found;
|
||||
use crate::file_hosting::FileHostingError;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user