Watch
0
0
Fork
You've already forked hyperhive
0

notify router: read custom flows and disabled built-ins from a stored document

This commit is contained in:
atlas 2026-10-24 03:44:00 +02:00 • committed by mara
commit bb08fac33c
11 changed files with 1418 additions and 342 deletions

View file

@ -4,7 +4,8 @@
//! (`swarm_wire::forge_events`), runs every flow over each delivery
//! ([`flow`], [`route`]), and queues the todo ops the flows emit on each
//! recipient agent's subject of `ROUTER_TODOS` (`swarm_wire::router_todo`).
//! Each agent's harness applies them to its own todo list.
//! Each agent's harness applies them to its own todo list. The flows are the
//! built-in ones, changed by the `notify-flows` document ([`stored`]).
//!
//! Per issue it keeps a snapshot in its state bucket ([`event::Snapshot`]):
//! the assignees it last saw and the agents it queued a todo for. An event is
@ -31,6 +32,7 @@ mod event;
mod flow;
mod route;
mod settle;
mod stored;
/// The cert-auth role this service logs in to the store as. `swarm-bao.nix`
/// writes it, matching the leaf's subject.
@ -83,17 +85,7 @@ async fn main() -> Result<()> {
})
.await?;
let flows: Vec<flow::Flow> = flow::builtins()
.into_iter()
.filter(|f| match f.validate() {
Ok(()) => true,
Err(reason) => {
tracing::error!(flow = %f.id, %reason, "notify router: skipping a flow that is not a tree");
false
}
})
.collect();
let mut router = Router::open(&queue, flows).await?;
let mut router = Router::open(&queue).await?;
tracing::info!(
stream = forge_events::STREAM,
"notify router: routing forge events"
@ -113,12 +105,12 @@ struct Router {
js: jetstream::Context,
events: jetstream::consumer::Consumer<pull::Config>,
state: kv::Store,
flows: Vec<flow::Flow>,
flows: stored::Flows,
roster: Option<(Instant, BTreeSet<String>)>,
}
impl Router {
async fn open(queue: &async_nats::Client, flows: Vec<flow::Flow>) -> Result<Self> {
async fn open(queue: &async_nats::Client) -> Result<Self> {
let js = jetstream::new(queue.clone());
let events = swarm_queue_client::forge_events::open_or_create(queue)
.await
@ -154,7 +146,7 @@ impl Router {
js,
events,
state,
flows,
flows: stored::Flows::builtins(),
roster: None,
})
}
@ -193,8 +185,9 @@ impl Router {
}),
None => event::Snapshot::default(),
};
self.flows.refresh(&self.js).await;
let roster = self.roster().await.map_err(Skip::Retry)?;
let routed = route::route(&event_type, &delivery, &snapshot, &self.flows, |a| {
let routed = route::route(&event_type, &delivery, &snapshot, &self.flows.active, |a| {
roster.contains(a)
});
for action in &routed.actions {