Allow first SQUID startup to complete large database imports

This commit is contained in:
Дмитрий committed 2026-10-06 10:12:13 +05:00
1 parent 171d9a2bf8
commit 6aea9011f9
2 files changed
+30 -2

No files matched your search

+23 -2
View File
@@ -31,8 +31,9 @@ impl Verb {
}
}
fn timeout(self) -> Duration {
fn timeout(self, root: &Path) -> Duration {
match self {
Verb::StartAll | Verb::StartWorld if squid_enabled(root) => Duration::from_secs(1800),
Verb::StartAll | Verb::StartWorld => Duration::from_secs(420),
Verb::StartMysql => Duration::from_secs(120),
Verb::StopAll => Duration::from_secs(240),
@@ -40,6 +41,14 @@ impl Verb {
}
}
fn squid_enabled(root: &Path) -> bool {
let active = root.join("Core/configs/modules/playerbots.conf");
let path = if active.exists() { active } else { root.join("Core/configs/modules/playerbots.conf.dist") };
std::fs::read(path).ok().and_then(|bytes| crate::config::parser::ConfFile::parse_bytes(&bytes).ok())
.is_some_and(|config| config.get("AiPlayerbot.Enabled").is_none_or(|value|
!matches!(value.trim().trim_matches('"').to_ascii_lowercase().as_str(), "0" | "false" | "no" | "off")))
}
#[derive(Debug, Clone, Serialize)]
pub struct DriverOutcome {
pub ok: bool,
@@ -149,7 +158,7 @@ fn run_inner(root: &Path, verb: Verb, validating_update: bool) -> Result<DriverO
let _ = stderr.read_to_string(&mut s);
s
});
let deadline = Instant::now() + verb.timeout();
let deadline = Instant::now() + verb.timeout(&root);
let status = loop {
if let Some(st) = child.try_wait()? {
break Some(st);
@@ -230,6 +239,18 @@ pub(crate) fn startup_failure(root: &Path, started: &DriverOutcome) -> String {
mod tests {
use super::*;
#[test]
fn large_squid_provisioning_has_time_to_finish_without_extending_shutdown() {
let folder = tempfile::tempdir().unwrap();
let modules = folder.path().join("Core/configs/modules");
std::fs::create_dir_all(&modules).unwrap();
std::fs::write(modules.join("playerbots.conf.dist"), "AiPlayerbot.Enabled = 1\n").unwrap();
assert_eq!(Verb::StartAll.timeout(folder.path()), Duration::from_secs(1800));
assert_eq!(Verb::StopAll.timeout(folder.path()), Duration::from_secs(240));
std::fs::write(modules.join("playerbots.conf"), "AiPlayerbot.Enabled = 0\n").unwrap();
assert_eq!(Verb::StartWorld.timeout(folder.path()), Duration::from_secs(420));
}
#[test]
fn translates_known_launcher_messages() {
assert_eq!(translate("RuntimeError: Port 8085 is already used. Stop the other server"), ErrorCode::PortInUse);