Watch
0
0
Fork
You've already forked hyperhive
0

archetype flows on the board list the agents the router sends to, and the docs say a switch-off key outlives its flow

This commit is contained in:
atlas 2026-11-11 20:45:07 +01:00 • committed by mara
commit 13ff33ead0

View file

@ -35,7 +35,7 @@ use std::time::{Duration, Instant};
use anyhow::{Context as _, Result, bail};
use async_nats::jetstream::{self, consumer::pull, kv, message::PublishMessage};
use futures_util::{StreamExt as _, TryStreamExt as _};
use futures_util::StreamExt as _;
use metrics::Handled;
use swarm_queue_client::{ClientSecret, QueueConfig};
use swarm_secret_client::stored_secret::StoredSecret;
@ -366,35 +366,18 @@ impl Router {
{
return Ok(agents.clone());
}
let agents = roster_of(&self.js).await?;
let agents = roster_of(&self.nats).await?;
self.roster = Some((Instant::now(), agents.clone()));
Ok(agents)
}
}
/// The agents of this swarm, read from the agent-status bucket.
pub(crate) async fn roster_of(js: &jetstream::Context) -> Result<BTreeSet<String>> {
let bucket = swarm_wire::agent_status::BUCKET;
let stream = js
.get_stream(format!("KV_{bucket}"))
pub(crate) async fn roster_of(client: &async_nats::Client) -> Result<BTreeSet<String>> {
swarm_queue_client::agent_status::roster(client)
.await
.context("opening the agent-status bucket")?;
let subjects: Vec<(String, usize)> = stream
.info_with_subjects(format!("$KV.{bucket}.>"))
.await
.context("listing agent-status keys")?
.try_collect()
.await
.context("listing agent-status keys")?;
let prefix = format!("$KV.{bucket}.");
let agents: BTreeSet<String> = subjects
.into_iter()
.filter_map(|(subject, _)| {
let key = subject.strip_prefix(&prefix)?;
swarm_wire::agent_status::split_key(key).map(|(_, agent)| agent.to_owned())
})
.collect();
Ok(agents)
.map_err(|e| anyhow::anyhow!("{e}"))
.context("listing the agents in the agent-status bucket")
}
/// Why an event was not handled.