O4: parallel workers, locks, provider quota (#12)

This commit was merged in pull request #12.
This commit is contained in:
hermes committed 2026-11-12 23:52:22 +00:00
1 parent afafc41376
commit 06662a085f
10 files changed
+410 -43

No files matched your search

+25
View File
@@ -34,6 +34,13 @@ pub struct Profile {
/// Extra hx attempts after a red gate (default 2). 0 = fail straight to needs-human.
#[serde(default = "default_retries")]
pub max_retries: u32,
/// Parallel runs for `orch pull` (default 1).
#[serde(default = "one")]
pub workers: u32,
/// Provider account this profile bills to; profiles sharing a login set the same name. Default: profile name.
pub account: Option<String>,
/// Max simultaneous runs on the account across all orch processes (default = workers).
pub max_concurrent: Option<u32>,
#[serde(default)]
pub budget: Budget,
/// Default repo for tasks that name none (`orch pull`).
@@ -42,6 +49,10 @@ pub struct Profile {
pub sink: Option<crate::adapter::Adapter>,
}
fn one() -> u32 {
1
}
fn default_retries() -> u32 {
2
}
@@ -53,6 +64,9 @@ fn default_hx() -> String {
impl Profile {
pub fn parse(s: &str) -> Result<Self> {
let p: Profile = toml::from_str(s)?;
if p.workers == 0 || p.max_concurrent == Some(0) {
bail!("workers and max_concurrent must be >= 1");
}
if p.yolo && !p.sandbox {
bail!("yolo = true requires sandbox = true");
}
@@ -71,6 +85,10 @@ impl Profile {
Self::parse(&s).with_context(|| path.display().to_string())
}
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {
self.account.as_deref().unwrap_or(profile)
}
pub fn wall_secs(&self) -> u64 {
self.budget.wall_secs.unwrap_or(1800)
}
@@ -83,6 +101,7 @@ mod tests {
#[test]
fn minimal_and_full() {
let p = Profile::parse("").unwrap();
assert_eq!((p.workers, p.account("x")), (1, "x"));
assert_eq!(
(p.hx.as_str(), p.wall_secs(), p.gate.is_none()),
("hx", 1800, true)
@@ -97,6 +116,12 @@ mod tests {
);
}
#[test]
fn rejects_zero_workers() {
assert!(Profile::parse("workers = 0").is_err());
assert!(Profile::parse("max_concurrent = 0").is_err());
}
#[test]
fn rejects_yolo_without_sandbox_and_unknown_keys() {
assert!(Profile::parse("yolo=true").is_err());