hive-c0re: reconcile declared agents periodically, with backoff
This commit is contained in:
parent
7468aa4cff
commit
b8c07a5492
1 changed files with 516 additions and 9 deletions
|
|
@ -224,6 +224,36 @@ impl JobQueue {
|
|||
Ok(Some(named))
|
||||
}
|
||||
|
||||
/// Queue a lone `Reconcile` for `agent` unless any queued or running node
|
||||
/// already targets it.
|
||||
///
|
||||
/// `None` means the agent is busy: an update, create, destroy, power op or
|
||||
/// earlier reconcile is live, and the work in flight converges it (or
|
||||
/// decides not to). The check and the insert share one lock, so a caller
|
||||
/// racing another insert cannot queue behind a node it did not see. The
|
||||
/// shape is the down-agent restart: a `Reconcile` on the agent's lease,
|
||||
/// which reads the agent's power intent when it runs.
|
||||
///
|
||||
/// # Errors
|
||||
/// 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 {
|
||||
return Ok(None);
|
||||
}
|
||||
let targets = [(agent.to_owned(), false)];
|
||||
let named = inner
|
||||
.insert_job(None, |b| power::restart_nodes(b, &targets, false))
|
||||
.map_err(|e| anyhow::anyhow!("job_queue: graph insert failed: {e}"))?;
|
||||
drop(inner);
|
||||
self.notify.notify_one();
|
||||
Ok(Some(named))
|
||||
}
|
||||
|
||||
/// The scheduler itself, for `hive_jobq`'s run-loop seam
|
||||
/// (`Scheduler::claim_next`), which takes exactly this type.
|
||||
///
|
||||
|
|
|
|||
Loading…
Reference in a new issue