hive-bash-mcp: publish each task's status and output to the swarm queue
This commit is contained in:
parent
faadc5abe2
commit
c0b9c1778c
1 changed files with 841 additions and 211 deletions
|
|
@ -197,7 +197,10 @@ fn write_task(task: &TaskFile) -> std::io::Result<()> {
|
|||
let dest = paths::task_json(&task.id);
|
||||
let tmp = dest.with_extension("json.tmp");
|
||||
std::fs::write(&tmp, &json)?;
|
||||
std::fs::rename(&tmp, &dest)
|
||||
std::fs::rename(&tmp, &dest)?;
|
||||
// Every state change is written here, so the swarm hears of each one.
|
||||
crate::swarm_term::status(task);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Read a task file. Returns `None` if the file doesn't exist or is
|
||||
|
|
@ -626,6 +629,7 @@ async fn run_task(mut task: TaskFile, socket: &Path, cgroups: Option<&RunCgroups
|
|||
);
|
||||
|
||||
let cgroup = cgroups.and_then(|cgroups| task_cgroup(cgroups, &id));
|
||||
let follower = crate::swarm_term::follow(&id, out_path.clone(), err_path.clone());
|
||||
let outcome = exec_cmd(
|
||||
&task.cmd,
|
||||
&out_path,
|
||||
|
|
@ -637,6 +641,10 @@ async fn run_task(mut task: TaskFile, socket: &Path, cgroups: Option<&RunCgroups
|
|||
)
|
||||
.await;
|
||||
drop(cgroup);
|
||||
// The last output goes out before the terminal status does.
|
||||
if let Some(follower) = follower {
|
||||
follower.finish().await;
|
||||
}
|
||||
|
||||
// Deregister before writing terminal state — the task is no longer killable.
|
||||
running().lock().unwrap().remove(&id);
|
||||
|
|
|
|||
Loading…
Reference in a new issue