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

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-05 00:13:10 -03:00
parent 645a7936c5
commit eba075bb9d

View file

@ -869,46 +869,35 @@ 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() if let Ok(s) = self_owned.get_secret(&bot_path).await {
.worker_threads(1) if !s.is_empty() && s.contains_key("smtp_from") {
.build(); return Some(s);
let result = if let Ok(rt) = rt {
rt.block_on(async move {
if let Ok(s) = self_owned.get_secret(&bot_path).await {
if !s.is_empty() && s.contains_key("smtp_from") {
return Some(s);
}
} }
if let Ok(s) = self_owned.get_secret(&default_path).await { }
if !s.is_empty() && s.contains_key("smtp_from") { if let Ok(s) = self_owned.get_secret(&default_path).await {
return Some(s); if !s.is_empty() && s.contains_key("smtp_from") {
} return Some(s);
} }
if let Ok(s) = self_owned.get_secret(SecretPaths::EMAIL).await { }
if !s.is_empty() && s.contains_key("smtp_from") { if let Ok(s) = self_owned.get_secret(SecretPaths::EMAIL).await {
return Some(s); if !s.is_empty() && s.contains_key("smtp_from") {
} return Some(s);
} }
None }
})
} else {
None None
}; });
let _ = tx.send(result); if let Some(secrets) = result {
}); return (
secrets.get("smtp_host").cloned().unwrap_or_default(),
if let Ok(Some(secrets)) = rx.recv_timeout(std::time::Duration::from_secs(5)) { secrets.get("smtp_port").and_then(|p| p.parse().ok()).unwrap_or(587),
return ( secrets.get("smtp_user").cloned().unwrap_or_default(),
secrets.get("smtp_host").cloned().unwrap_or_default(), secrets.get("smtp_password").cloned().unwrap_or_default(),
secrets.get("smtp_port").and_then(|p| p.parse().ok()).unwrap_or(587), secrets.get("smtp_from").cloned().unwrap_or_default(),
secrets.get("smtp_user").cloned().unwrap_or_default(), );
secrets.get("smtp_password").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())
} }