fix: use existing tokio Handle instead of spawning new runtime for email config
All checks were successful
BotServer CI/CD / build (push) Successful in 4m32s
All checks were successful
BotServer CI/CD / build (push) Successful in 4m32s
This commit is contained in:
parent
645a7936c5
commit
eba075bb9d
1 changed files with 24 additions and 35 deletions
|
|
@ -869,15 +869,9 @@ impl SecretsManager {
|
||||||
let bot_path = format!("gbo/bots/{}/email", bot_id);
|
let bot_path = format!("gbo/bots/{}/email", bot_id);
|
||||||
let default_path = "gbo/bots/default/email".to_string();
|
let default_path = "gbo/bots/default/email".to_string();
|
||||||
let self_owned = self.clone();
|
let self_owned = self.clone();
|
||||||
let (tx, rx) = std::sync::mpsc::channel();
|
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
if let Ok(handle) = tokio::runtime::Handle::try_current() {
|
||||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
let result = handle.block_on(async move {
|
||||||
.enable_all()
|
|
||||||
.worker_threads(1)
|
|
||||||
.build();
|
|
||||||
let result = if let Ok(rt) = rt {
|
|
||||||
rt.block_on(async move {
|
|
||||||
if let Ok(s) = self_owned.get_secret(&bot_path).await {
|
if let Ok(s) = self_owned.get_secret(&bot_path).await {
|
||||||
if !s.is_empty() && s.contains_key("smtp_from") {
|
if !s.is_empty() && s.contains_key("smtp_from") {
|
||||||
return Some(s);
|
return Some(s);
|
||||||
|
|
@ -894,14 +888,8 @@ impl SecretsManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
let _ = tx.send(result);
|
|
||||||
});
|
});
|
||||||
|
if let Some(secrets) = result {
|
||||||
if let Ok(Some(secrets)) = rx.recv_timeout(std::time::Duration::from_secs(5)) {
|
|
||||||
return (
|
return (
|
||||||
secrets.get("smtp_host").cloned().unwrap_or_default(),
|
secrets.get("smtp_host").cloned().unwrap_or_default(),
|
||||||
secrets.get("smtp_port").and_then(|p| p.parse().ok()).unwrap_or(587),
|
secrets.get("smtp_port").and_then(|p| p.parse().ok()).unwrap_or(587),
|
||||||
|
|
@ -910,6 +898,7 @@ impl SecretsManager {
|
||||||
secrets.get("smtp_from").cloned().unwrap_or_default(),
|
secrets.get("smtp_from").cloned().unwrap_or_default(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
(String::new(), 587, String::new(), String::new(), String::new())
|
(String::new(), 587, String::new(), String::new(), String::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue