huskies: merge 998

This commit is contained in:
dave
2026-05-13 19:29:08 +00:00
parent 75dc1fc15a
commit bbdee1239b
9 changed files with 427 additions and 586 deletions
+34 -3
View File
@@ -1,9 +1,40 @@
//! Event bus for pipeline state transitions.
#![allow(unused_imports, dead_code)]
use chrono::{DateTime, Utc};
use std::sync::OnceLock;
use tokio::sync::broadcast;
use super::{BranchName, PipelineEvent, Stage, StoryId};
use super::{PipelineEvent, Stage, StoryId};
// ── Static transition broadcast channel ─────────────────────────────────────
static TRANSITION_TX: OnceLock<broadcast::Sender<TransitionFired>> = OnceLock::new();
fn get_or_init_tx() -> &'static broadcast::Sender<TransitionFired> {
TRANSITION_TX.get_or_init(|| {
let (tx, _) = broadcast::channel(256);
tx
})
}
/// Subscribe to all pipeline stage transitions.
///
/// Every call to [`apply_transition`][super::apply_transition] broadcasts the
/// resulting [`TransitionFired`] on this channel. Returns a new receiver that
/// replays events from the moment of subscription. Lagged receivers silently
/// skip missed events — callers should handle
/// [`broadcast::error::RecvError::Lagged`].
pub fn subscribe_transitions() -> broadcast::Receiver<TransitionFired> {
get_or_init_tx().subscribe()
}
/// Broadcast `fired` to all active transition subscribers.
///
/// Called from [`apply_transition`][super::apply] after writing the new stage
/// to the CRDT. No-ops safely when there are no subscribers.
pub(super) fn try_broadcast(fired: &TransitionFired) {
let _ = get_or_init_tx().send(fired.clone());
}
/// Fired when a pipeline stage transition completes.
#[derive(Debug, Clone)]
@@ -55,9 +86,9 @@ impl Default for EventBus {
#[cfg(test)]
mod tests {
use super::super::BranchName;
use super::*;
use std::num::NonZeroU32;
use std::sync::{Arc, Mutex};
fn nz(n: u32) -> NonZeroU32 {
NonZeroU32::new(n).unwrap()