mirror of
https://github.com/sadoyan/aralez.git
synced 2026-05-30 03:44:06 +08:00
Merge pull request #34 from Taqman-probe/fix/failed-hot-reload-config
Add retry mechanism for configuration parsing failures
This commit is contained in:
@@ -21,8 +21,38 @@ pub static DOMAINS: LazyLock<DashMap<String, bool>> = LazyLock::new(DashMap::new
|
|||||||
pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>, String) {
|
pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>, String) {
|
||||||
let mut conf_files = Vec::new();
|
let mut conf_files = Vec::new();
|
||||||
let yaml_data = match kind {
|
let yaml_data = match kind {
|
||||||
"filepath" => match fs::read_to_string(d) {
|
"filepath" => {
|
||||||
Ok(data) => {
|
let mut data = String::new();
|
||||||
|
let mut last_error = None;
|
||||||
|
for _ in 0..5 {
|
||||||
|
match fs::read_to_string(d) {
|
||||||
|
Ok(content) => {
|
||||||
|
if !content.trim().is_empty() {
|
||||||
|
data = content;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
last_error = Some(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||||
|
}
|
||||||
|
if data.is_empty() {
|
||||||
|
let err_msg = match last_error {
|
||||||
|
Some(e) => {
|
||||||
|
error!("Reading: {}: {:?}", d, e);
|
||||||
|
e.to_string()
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
error!("Reading: {}: File is empty after retries", d);
|
||||||
|
"File is empty".to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
warn!("Running with empty upstreams list, update it via API");
|
||||||
|
return (None, err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
let mut confdir = Path::new(d).parent().unwrap().to_path_buf();
|
let mut confdir = Path::new(d).parent().unwrap().to_path_buf();
|
||||||
let mut autocfg = Path::new(d).parent().unwrap().to_path_buf();
|
let mut autocfg = Path::new(d).parent().unwrap().to_path_buf();
|
||||||
|
|
||||||
@@ -65,12 +95,7 @@ pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>,
|
|||||||
|
|
||||||
info!("Reading upstreams from {}", d);
|
info!("Reading upstreams from {}", d);
|
||||||
data
|
data
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Reading: {}: {:?}", d, e);
|
|
||||||
warn!("Running with empty upstreams list, update it via API");
|
|
||||||
return (None, e.to_string());
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"content" => {
|
"content" => {
|
||||||
info!("Reading upstreams from API post body");
|
info!("Reading upstreams from API post body");
|
||||||
|
|||||||
Reference in New Issue
Block a user