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:
parent
68c24643f6
commit
13ff33ead0
1 changed files with 66 additions and 30 deletions
|
|
@ -20,3 +20,34 @@ pub async fn open_or_create(
|
|||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// The agents of the swarm: the agent names in the bucket's keys
|
||||
/// (`<hive>.<agent>`), read from the stream's subject list. This is the
|
||||
/// roster the notification router sends to.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The bucket's stream cannot be opened or its subjects listed.
|
||||
#[cfg(feature = "kv")]
|
||||
pub async fn roster(
|
||||
client: &async_nats::Client,
|
||||
) -> Result<std::collections::BTreeSet<String>, Box<dyn std::error::Error + Send + Sync>> {
|
||||
use futures_util::TryStreamExt as _;
|
||||
|
||||
let bucket = swarm_wire::agent_status::BUCKET;
|
||||
let js = async_nats::jetstream::new(client.clone());
|
||||
let stream = js.get_stream(format!("KV_{bucket}")).await?;
|
||||
let subjects: Vec<(String, usize)> = stream
|
||||
.info_with_subjects(format!("$KV.{bucket}.>"))
|
||||
.await?
|
||||
.try_collect()
|
||||
.await?;
|
||||
let prefix = format!("$KV.{bucket}.");
|
||||
Ok(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())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue