1
0
Files
AstralRinth/src/health/pod.rs
Redblueflame efa8d5c575 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>
2021-09-20 21:26:16 -07:00

33 lines
915 B
Rust

use std::sync::{RwLock, Arc};
#[derive(Clone, Debug)]
pub struct PodInfo {
pub pod_name: String,
pub node_name: String,
pod_id: Arc<RwLock<Option<String>>>,
}
impl PodInfo {
pub fn new() -> Self {
Self {
pod_name: dotenv::var("POD_NAME").unwrap_or("DEV".to_string()),
node_name: dotenv::var("NODE_NAME").unwrap_or("self-hosted".to_string()),
pod_id: Arc::new(RwLock::new(None))
}
}
pub fn get_id(&self) -> String {
{
let lock = self.pod_id.read().unwrap();
if lock.is_some() {
return lock.clone().unwrap();
}
}
let mut lock = self.pod_id.write().unwrap();
let id = self.generate_id();
lock.replace(id.clone());
id
}
fn generate_id(&self) -> String {
base64::encode(format!("{}-{}", self.node_name, self.pod_name))
}
}