MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / spawn_event_trigger_processor

Function spawn_event_trigger_processor

nodedb/src/control/event_trigger.rs:23–56  ·  view source on GitHub ↗

Spawn the event trigger processor as a background tokio task registered with the shutdown loop registry. The processor exits on shutdown signal or when the change-stream broadcast channel closes.

(shared: Arc<SharedState>)

Source from the content-addressed store, hash-verified

21/// exits on shutdown signal or when the change-stream
22/// broadcast channel closes.
23pub fn spawn_event_trigger_processor(shared: Arc<SharedState>) {
24 let mut subscription = shared.change_stream.subscribe(None, None);
25 let registry = Arc::clone(&shared.loop_registry);
26 let watch = Arc::clone(&shared.shutdown);
27
28 crate::control::shutdown::spawn_loop(
29 &registry,
30 &watch,
31 "event_trigger_processor",
32 move |mut shutdown| async move {
33 loop {
34 tokio::select! {
35 _ = shutdown.wait_cancelled() => {
36 debug!("event trigger processor shutting down");
37 break;
38 }
39 msg = subscription.recv_filtered() => match msg {
40 Ok(event) => process_event(&shared, &event).await,
41 Err(tokio::sync::broadcast::error::RecvError::Lagged(n)) => {
42 warn!(
43 lagged = n,
44 "event trigger processor fell behind; skipped {n} events"
45 );
46 }
47 Err(tokio::sync::broadcast::error::RecvError::Closed) => {
48 debug!("change stream closed; event trigger processor stopping");
49 break;
50 }
51 },
52 }
53 }
54 },
55 );
56}
57
58/// Process a single change event against all matching EventDefinitions.
59async fn process_event(shared: &SharedState, event: &ChangeEvent) {

Callers 1

spawn_background_loopsFunction · 0.85

Calls 2

spawn_loopFunction · 0.85
subscribeMethod · 0.45

Tested by

no test coverage detected