feat(#1178): add kill + update tools to AgentServer (topology-scoped)
This commit is contained in:
parent
29c7f64bd3
commit
2722e1548c
3 changed files with 98 additions and 0 deletions
|
|
@ -371,6 +371,60 @@ async fn dispatch(req: &AgentRequest, agent: &str, coord: &Arc<Coordinator>) ->
|
|||
coord.emit_rebuild_queue_snapshot();
|
||||
AgentResponse::Ok
|
||||
}
|
||||
AgentRequest::Kill { name } => {
|
||||
if !crate::topology::children_of(agent)
|
||||
.iter()
|
||||
.any(|c| c == name)
|
||||
{
|
||||
return AgentResponse::Err {
|
||||
message: format!(
|
||||
"agent `{agent}` cannot kill `{name}`: \
|
||||
not a direct child in the topology tree"
|
||||
),
|
||||
};
|
||||
}
|
||||
tracing::info!(%agent, %name, "agent: kill child");
|
||||
let result: anyhow::Result<()> = async {
|
||||
crate::lifecycle::kill(name).await?;
|
||||
coord.unregister_agent(name);
|
||||
Ok(())
|
||||
}
|
||||
.await;
|
||||
match result {
|
||||
Ok(()) => {
|
||||
coord.notify_manager(&hive_sh4re::HelperEvent::Killed {
|
||||
agent: name.clone(),
|
||||
});
|
||||
AgentResponse::Ok
|
||||
}
|
||||
Err(e) => AgentResponse::Err {
|
||||
message: format!("{e:#}"),
|
||||
},
|
||||
}
|
||||
}
|
||||
AgentRequest::Update { name } => {
|
||||
if !crate::topology::children_of(agent)
|
||||
.iter()
|
||||
.any(|c| c == name)
|
||||
{
|
||||
return AgentResponse::Err {
|
||||
message: format!(
|
||||
"agent `{agent}` cannot rebuild `{name}`: \
|
||||
not a direct child in the topology tree"
|
||||
),
|
||||
};
|
||||
}
|
||||
tracing::info!(%agent, %name, "agent: enqueue rebuild for child");
|
||||
coord.rebuild_queue.enqueue(
|
||||
crate::rebuild_queue::QueueKind::Rebuild,
|
||||
name.to_owned(),
|
||||
crate::rebuild_queue::QueueSource::Manual,
|
||||
format!("agent `{agent}` update tool"),
|
||||
None,
|
||||
);
|
||||
coord.emit_rebuild_queue_snapshot();
|
||||
AgentResponse::Ok
|
||||
}
|
||||
// Manager-only variants are not valid on the agent socket.
|
||||
_ => AgentResponse::Err {
|
||||
message: "request not supported on agent socket".to_owned(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue