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

+19 -7
View File
@@ -25,14 +25,14 @@ pub struct Task {
pub extra: Map<String, Value>,
}
pub trait Source {
pub trait Source: Send + Sync {
fn list(&self) -> Result<Vec<Task>>;
/// false = somebody else got it; skip silently.
fn claim(&self, t: &Task) -> Result<bool>;
fn report(&self, t: &Task, r: &Run) -> Result<()>;
}
pub trait Sink {
pub trait Sink: Send + Sync {
/// Called for runs that ended `done`. Returns a URL or note to store on the run.
fn publish(&self, t: &Task, r: &Run) -> Result<Option<String>>;
}
@@ -121,6 +121,18 @@ impl DirSource {
}
}
impl DirSource {
/// Quota requeue: the task goes back into the queue for the next pull.
fn mv_back(&self, id: &str) -> Result<bool> {
let name = format!("{id}.md");
match std::fs::rename(self.0.join(".running").join(&name), self.0.join(&name)) {
Ok(()) => Ok(true),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(false),
Err(e) => Err(e.into()),
}
}
}
impl Source for DirSource {
fn list(&self) -> Result<Vec<Task>> {
let mut v = vec![];
@@ -141,12 +153,12 @@ impl Source for DirSource {
self.mv(&t.id, "", ".running")
}
fn report(&self, t: &Task, r: &Run) -> Result<()> {
let to = if r.status == crate::state::Status::Done {
".done"
} else {
".failed"
use crate::state::Status;
match r.status {
Status::Done => self.mv(&t.id, ".running", ".done")?,
Status::Requeued => self.mv_back(&t.id)?,
_ => self.mv(&t.id, ".running", ".failed")?,
};
self.mv(&t.id, ".running", to)?;
Ok(())
}
}