reconcile tick: create a placed agent whose deploy event was missed
The swarm's deploy event is core NATS. The wanted-state declaration lands before the build, so its create fails on no record, and only the event re-drives it; a hive that missed the event had nothing to retry. wanted.rs now remembers which agents the last declaration places with a container. Each tick, a placed agent with no container whose record says the builder pushed its closure gets its first deploy through JobQueue::insert_first_deploy_if_idle, which queues nothing while any node targets the agent. Record reads and creates back off like restarts, in a history of their own.
This commit is contained in:
parent
887ea26c56
commit
ad30b7ea31
1 changed files with 439 additions and 17 deletions
|
|
@ -98,6 +98,14 @@ pub struct RunningTransient {
|
|||
/// satisfy).
|
||||
type Sched = Scheduler<NodeKind, Resource>;
|
||||
|
||||
/// Whether any queued or running node targets `agent`.
|
||||
fn agent_busy(sched: &Sched, agent: &str) -> bool {
|
||||
sched
|
||||
.graph()
|
||||
.nodes()
|
||||
.any(|n| !n.state.is_terminal() && n.payload.agent() == agent)
|
||||
}
|
||||
|
||||
/// The queue. Lives on `Coordinator` (one per hive-c0re process); a single
|
||||
/// scheduler task ([`scheduler::run_worker`]) drives it.
|
||||
pub struct JobQueue {
|
||||
|
|
@ -224,6 +232,27 @@ impl JobQueue {
|
|||
Ok(Some(named))
|
||||
}
|
||||
|
||||
/// Queue `agent`'s first deploy unless any queued or running node targets
|
||||
/// it, by the same rule as [`Self::insert_reconcile_if_idle`].
|
||||
///
|
||||
/// `None` means the agent is busy: a first deploy, or any other work on it,
|
||||
/// is in flight. The check and the insert share one lock.
|
||||
///
|
||||
/// # Errors
|
||||
/// Propagates a graph-insert error.
|
||||
pub fn insert_first_deploy_if_idle(&self, agent: &str) -> anyhow::Result<Option<Vec<NodeId>>> {
|
||||
let mut inner = self.lock();
|
||||
if agent_busy(&inner, agent) {
|
||||
return Ok(None);
|
||||
}
|
||||
let named = inner
|
||||
.insert_job(None, |b| templates::first_deploy(b, agent))
|
||||
.map_err(|e| anyhow::anyhow!("job_queue: graph insert failed: {e}"))?;
|
||||
drop(inner);
|
||||
self.notify.notify_one();
|
||||
Ok(Some(named))
|
||||
}
|
||||
|
||||
/// Queue a lone `Reconcile` for `agent` unless any queued or running node
|
||||
/// already targets it.
|
||||
///
|
||||
|
|
@ -238,11 +267,7 @@ impl JobQueue {
|
|||
/// Propagates a graph-insert error.
|
||||
pub fn insert_reconcile_if_idle(&self, agent: &str) -> anyhow::Result<Option<Vec<NodeId>>> {
|
||||
let mut inner = self.lock();
|
||||
let busy = inner
|
||||
.graph()
|
||||
.nodes()
|
||||
.any(|n| !n.state.is_terminal() && n.payload.agent() == agent);
|
||||
if busy {
|
||||
if agent_busy(&inner, agent) {
|
||||
return Ok(None);
|
||||
}
|
||||
let targets = [(agent.to_owned(), false)];
|
||||
|
|
|
|||
Loading…
Reference in a new issue