feat: database status for status checker

This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-11-20 00:16:31 +03:00
parent c61ebe127a
commit b86580f5ba
2 changed files with 22 additions and 4 deletions

View file

@ -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
}
}