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_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())
}
#[cfg(test)]
mod tests {
use super::*;
#[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);
}
}