MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / run

Method run

crates/openshell-sandbox/src/activity_aggregator.rs:48–90  ·  view source on GitHub ↗
(mut self, flush_callback: F)

Source from the content-addressed store, hash-verified

46 }
47
48 pub async fn run<F, Fut>(mut self, flush_callback: F)
49 where
50 F: Fn(FlushableActivitySummary) -> Fut + Send + 'static,
51 Fut: Future<Output = ()> + Send + 'static,
52 {
53 let (flush_tx, mut flush_rx) =
54 mpsc::channel::<FlushableActivitySummary>(ACTIVITY_FLUSH_QUEUE_CAPACITY);
55 tokio::spawn(async move {
56 while let Some(summary) = flush_rx.recv().await {
57 flush_callback(summary).await;
58 }
59 });
60
61 let mut flush_interval =
62 tokio::time::interval(std::time::Duration::from_secs(self.flush_interval_secs));
63 flush_interval.tick().await;
64
65 loop {
66 tokio::select! {
67 event = self.rx.recv() => {
68 if let Some(event) = event {
69 self.ingest(event);
70 } else {
71 if let Some(summary) = self.drain() {
72 queue_flush_summary(&flush_tx, summary);
73 }
74 debug!("ActivityAggregator: channel closed, exiting");
75 return;
76 }
77 }
78 _ = flush_interval.tick() => {
79 if let Some(summary) = self.drain() {
80 debug!(
81 count = summary.network_activity_count,
82 denied = summary.denied_action_count,
83 "ActivityAggregator: flushing anonymous activity summary"
84 );
85 queue_flush_summary(&flush_tx, summary);
86 }
87 }
88 }
89 }
90 }
91
92 fn ingest(&mut self, event: ActivityEvent) {
93 self.network_activity_count = self.network_activity_count.saturating_add(1);

Callers

nothing calls this directly

Calls 1

spawnFunction · 0.50

Tested by

no test coverage detected