pub(crate) const GATE_ESCALATION_THRESHOLD_SECS: u64 = 30 * 60;
fn parse_gate_timeout(raw: Option<String>) -> u64 {
const SEVEN_DAYS: u64 = 7 * 24 * 60 * 60;
raw.and_then(|s| s.parse().ok()).unwrap_or(SEVEN_DAYS)
}
pub(crate) fn gate_timeout_secs() -> u64 {
parse_gate_timeout(std::env::var("DEVFLOW_GATE_TIMEOUT_SECS").ok())
}
fn parse_foreground_gate_timeout(raw: Option<String>) -> u64 {
const DEFAULT_SECS: u64 = 60;
raw.and_then(|s| s.parse().ok()).unwrap_or(DEFAULT_SECS)
}
pub(crate) fn foreground_gate_timeout_secs() -> u64 {
parse_foreground_gate_timeout(std::env::var("DEVFLOW_FOREGROUND_GATE_TIMEOUT_SECS").ok())
}
fn parse_checkout_lock_timeout(raw: Option<String>) -> std::time::Duration {
const DEFAULT_SECS: u64 = 120;
std::time::Duration::from_secs(raw.and_then(|s| s.parse().ok()).unwrap_or(DEFAULT_SECS))
}
pub(crate) fn checkout_lock_timeout() -> std::time::Duration {
parse_checkout_lock_timeout(std::env::var("DEVFLOW_CHECKOUT_LOCK_TIMEOUT_SECS").ok())
}
fn parse_gate_max_unattended_age(raw: Option<String>) -> u64 {
const SIX_HOURS: u64 = 6 * 60 * 60;
match raw.and_then(|s| s.parse::<u64>().ok()) {
Some(0) | None => SIX_HOURS,
Some(secs) => secs,
}
}
pub(crate) fn gate_max_unattended_age_secs() -> u64 {
parse_gate_max_unattended_age(std::env::var("DEVFLOW_GATE_MAX_UNATTENDED_AGE_SECS").ok())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn max_unattended_age_defaults_when_absent() {
assert_eq!(parse_gate_max_unattended_age(None), 6 * 60 * 60);
}
#[test]
fn max_unattended_age_parses_explicit_value() {
assert_eq!(parse_gate_max_unattended_age(Some("900".into())), 900);
}
#[test]
fn max_unattended_age_defaults_on_unparsable() {
assert_eq!(
parse_gate_max_unattended_age(Some("nonsense".into())),
6 * 60 * 60
);
}
#[test]
fn max_unattended_age_defaults_on_explicit_zero() {
assert_eq!(parse_gate_max_unattended_age(Some("0".into())), 6 * 60 * 60);
}
#[test]
fn parse_checkout_lock_timeout_defaults_and_parses() {
assert_eq!(
parse_checkout_lock_timeout(None),
std::time::Duration::from_secs(120)
);
assert_eq!(
parse_checkout_lock_timeout(Some("5".into())),
std::time::Duration::from_secs(5)
);
assert_eq!(
parse_checkout_lock_timeout(Some("nope".into())),
std::time::Duration::from_secs(120)
);
}
#[test]
fn parse_gate_timeout_env_override() {
const SEVEN_DAYS: u64 = 7 * 24 * 60 * 60;
assert_eq!(parse_gate_timeout(Some("42".into())), 42);
assert_eq!(parse_gate_timeout(Some("bad".into())), SEVEN_DAYS);
assert_eq!(parse_gate_timeout(None), SEVEN_DAYS);
}
#[test]
fn parse_foreground_gate_timeout_env_override() {
assert_eq!(parse_foreground_gate_timeout(Some("5".into())), 5);
assert_eq!(parse_foreground_gate_timeout(Some("bad".into())), 60);
assert_eq!(parse_foreground_gate_timeout(None), 60);
}
}