Reject invalid deployment configuration early

This commit is contained in:
ms2k 2026-07-19 02:01:37 +09:00
commit 0e351c3640

View file

@ -61,7 +61,7 @@ impl WorkerApplicationConfig {
endpoint: target.endpoint.clone(),
region: target.region.clone(),
});
Ok(Self {
let config = Self {
management: ManagementConfig::from_env(crate::COMPONENT_NAME)?,
database_url: required_env("DATABASE_URL")?,
database_connections: env_parse("REMORA_DATABASE_MAX_CONNECTIONS", "16")?,
@ -124,7 +124,9 @@ impl WorkerApplicationConfig {
"REMORA_HUGGING_FACE_ENDPOINT",
"https://huggingface.co",
),
})
};
validate_worker_timing(&config.coordination, &config.worker)?;
Ok(config)
}
}
@ -324,6 +326,27 @@ fn parse_scheme_ports(input: &str) -> Result<Vec<(String, u16)>, RuntimeError> {
.collect()
}
fn validate_worker_timing(
coordination: &StoreConfig,
worker: &WorkerConfig,
) -> Result<(), RuntimeError> {
if coordination.global_limit == 0
|| coordination.lease_ttl.is_zero()
|| coordination.reserve_ttl.is_zero()
|| coordination.progress_ttl.is_zero()
|| worker.local_limit == 0
|| worker.idle_delay.is_zero()
|| worker.renew_interval.is_zero()
|| worker.renew_interval >= coordination.lease_ttl
|| worker.cancel_poll_interval.is_zero()
{
return Err(RuntimeError::message(
"worker limits and timing must be positive, and renewal must precede lease expiry",
));
}
Ok(())
}
async fn wait_for_shutdown() -> Result<(), RuntimeError> {
#[cfg(unix)]
{
@ -387,4 +410,19 @@ mod tests {
assert!(parse_scheme_ports("https").is_err());
assert!(parse_cidrs("private").is_err());
}
#[test]
fn validates_worker_timing_before_external_connections() {
let coordination = StoreConfig {
global_limit: 1,
lease_ttl: Duration::from_secs(30),
reserve_ttl: Duration::from_secs(30),
progress_ttl: Duration::from_secs(60),
cancel_ttl: None,
};
let mut worker = WorkerConfig::default();
assert!(validate_worker_timing(&coordination, &worker).is_ok());
worker.renew_interval = coordination.lease_ttl;
assert!(validate_worker_timing(&coordination, &worker).is_err());
}
}