feat: ✨ database status for status checker
This commit is contained in:
parent
c61ebe127a
commit
b86580f5ba
2 changed files with 22 additions and 4 deletions
|
@ -1,8 +1,21 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use surrealdb::{
|
||||
engine::remote::ws::{Client, Ws},
|
||||
Surreal,
|
||||
};
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub async fn establish_connection() -> Surreal<Client> {
|
||||
Surreal::new::<Ws>("localhost:8000").await.unwrap()
|
||||
}
|
||||
|
||||
pub async fn is_alive(db: Surreal<Client>) -> bool {
|
||||
tokio::select! {
|
||||
db_result = db.health() => { match db_result {
|
||||
Ok(_) => true,
|
||||
Err(_) => false,
|
||||
} },
|
||||
_ = sleep(Duration::from_secs(1)) => false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue