mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 06:48:37 +08:00
Changed config file parser at startup, to keep initially dead nodes in list.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::utils::healthcheck;
|
||||
use crate::utils::state::{is_first_run, mark_not_first_run};
|
||||
use crate::utils::structs::*;
|
||||
use crate::utils::tools::{clone_dashmap, clone_dashmap_into, print_upstreams};
|
||||
use dashmap::DashMap;
|
||||
@@ -139,10 +140,16 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) {
|
||||
config.headers.insert(hostname.clone(), header_list);
|
||||
imtdashmap.insert(hostname.clone(), path_map);
|
||||
}
|
||||
let y = clone_dashmap(&imtdashmap);
|
||||
let r = healthcheck::initiate_upstreams(y).await;
|
||||
clone_dashmap_into(&r, &config.upstreams);
|
||||
println!("Upstream Config:");
|
||||
|
||||
if is_first_run() {
|
||||
clone_dashmap_into(&imtdashmap, &config.upstreams);
|
||||
mark_not_first_run();
|
||||
} else {
|
||||
let y = clone_dashmap(&imtdashmap);
|
||||
let r = healthcheck::initiate_upstreams(y).await;
|
||||
clone_dashmap_into(&r, &config.upstreams);
|
||||
}
|
||||
info!("Upstream Config:");
|
||||
print_upstreams(&config.upstreams);
|
||||
}
|
||||
}
|
||||
|
||||
30
src/utils/state.rs
Normal file
30
src/utils/state.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::RwLock;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SharedState {
|
||||
pub first_run: bool,
|
||||
}
|
||||
|
||||
pub static GLOBAL_STATE: Lazy<RwLock<SharedState>> = Lazy::new(|| RwLock::new(SharedState { first_run: true }));
|
||||
|
||||
pub fn mark_not_first_run() {
|
||||
let mut state = GLOBAL_STATE.write().unwrap();
|
||||
state.first_run = false;
|
||||
}
|
||||
|
||||
pub fn is_first_run() -> bool {
|
||||
let state = GLOBAL_STATE.read().unwrap();
|
||||
state.first_run
|
||||
}
|
||||
|
||||
/*
|
||||
impl SharedState {
|
||||
pub fn mark_first_run(&mut self) {
|
||||
self.first_run = false;
|
||||
}
|
||||
pub fn is_first_run(&self) -> bool {
|
||||
self.first_run
|
||||
}
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user