redis health check: return err when unable to connect
This commit is contained in:
parent
3132a48087
commit
9636180673
2 changed files with 25 additions and 30 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
@ -120,7 +120,7 @@ dependencies = [
|
|||
"serde_urlencoded",
|
||||
"sha-1",
|
||||
"slab",
|
||||
"time 0.2.26",
|
||||
"time 0.2.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -134,7 +134,7 @@ dependencies = [
|
|||
"futures-util",
|
||||
"serde 1.0.126",
|
||||
"serde_json",
|
||||
"time 0.2.26",
|
||||
"time 0.2.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -300,7 +300,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"socket2 0.3.19",
|
||||
"time 0.2.26",
|
||||
"time 0.2.27",
|
||||
"tinyvec",
|
||||
"url",
|
||||
]
|
||||
|
@ -923,7 +923,7 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
"rand 0.8.3",
|
||||
"sha2",
|
||||
"time 0.2.26",
|
||||
"time 0.2.27",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
|
@ -1805,7 +1805,7 @@ checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
|
|||
[[package]]
|
||||
name = "libmcaptcha"
|
||||
version = "0.1.4"
|
||||
source = "git+https://github.com/mCaptcha/libmcaptcha?branch=master#3db009977ae4144b0a3f71dbb310f62f11c31893"
|
||||
source = "git+https://github.com/mCaptcha/libmcaptcha?branch=master#52b7ebe4ca1263ad163ef6f36dcfaaa69610e637"
|
||||
dependencies = [
|
||||
"actix",
|
||||
"derive_builder 0.9.0",
|
||||
|
@ -3012,7 +3012,7 @@ dependencies = [
|
|||
"sqlx-rt",
|
||||
"stringprep",
|
||||
"thiserror",
|
||||
"time 0.2.26",
|
||||
"time 0.2.27",
|
||||
"url",
|
||||
"webpki",
|
||||
"webpki-roots",
|
||||
|
@ -3251,9 +3251,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.2.26"
|
||||
version = "0.2.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08a8cbfbf47955132d0202d1662f49b2423ae35862aee471f3ba4b133358f372"
|
||||
checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242"
|
||||
dependencies = [
|
||||
"const_fn",
|
||||
"libc",
|
||||
|
@ -3276,9 +3276,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "time-macros-impl"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa"
|
||||
checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f"
|
||||
dependencies = [
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use derive_builder::Builder;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use libmcaptcha::redis::{Redis, RedisConfig};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::data::SystemGroup;
|
||||
use crate::AppData;
|
||||
use crate::{GIT_COMMIT_HASH, VERSION};
|
||||
use crate::data::SystemGroup;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Builder, Serialize)]
|
||||
pub struct BuildDetails {
|
||||
|
@ -64,7 +64,7 @@ pub struct Health {
|
|||
redis: Option<bool>,
|
||||
}
|
||||
|
||||
impl Health {
|
||||
impl Health {
|
||||
fn is_redis(redis: &Option<bool>) -> bool {
|
||||
redis.is_none()
|
||||
}
|
||||
|
@ -77,9 +77,7 @@ async fn health(data: AppData) -> impl Responder {
|
|||
|
||||
let mut resp_builder = HealthBuilder::default();
|
||||
resp_builder.db(false);
|
||||
if resp_builder.redis.is_none() {
|
||||
//
|
||||
};
|
||||
resp_builder.redis = None;
|
||||
|
||||
if let Ok(mut con) = data.db.acquire().await {
|
||||
if con.ping().await.is_ok() {
|
||||
|
@ -87,21 +85,18 @@ async fn health(data: AppData) -> impl Responder {
|
|||
}
|
||||
};
|
||||
|
||||
match data.captcha {
|
||||
SystemGroup::Redis(_) => {
|
||||
let r = Redis::new(RedisConfig::Single(crate::SETTINGS.redis.as_ref().unwrap().url.clone())).await.unwrap();
|
||||
let status = r.get_client().ping().await;
|
||||
if let SystemGroup::Redis(_) = data.captcha {
|
||||
if let Ok(r) = Redis::new(RedisConfig::Single(
|
||||
crate::SETTINGS.redis.as_ref().unwrap().url.clone(),
|
||||
))
|
||||
.await
|
||||
{
|
||||
let status = r.get_client().ping().await;
|
||||
resp_builder.redis = Some(Some(status));
|
||||
|
||||
|
||||
// unimplemented!("GET PING FROM REDIS")
|
||||
//redis.get
|
||||
|
||||
},
|
||||
SystemGroup::Embedded(_) => {
|
||||
resp_builder.redis = None;
|
||||
},
|
||||
}
|
||||
} else {
|
||||
resp_builder.redis = Some(Some(false));
|
||||
}
|
||||
};
|
||||
|
||||
HttpResponse::Ok().json(resp_builder.build().unwrap())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue