MCPcopy Create free account
hub / github.com/GCWing/BitFun / dequeue_batch

Method dequeue_batch

src/crates/execution/agent-runtime/src/event_queue.rs:123–168  ·  view source on GitHub ↗

Dequeue batch of events

(&self, max_size: usize)

Source from the content-addressed store, hash-verified

121
122 /// Dequeue batch of events
123 pub async fn dequeue_batch(&self, max_size: usize) -> Vec<EventEnvelope> {
124 let mut batch = Vec::new();
125 let mut queue = self.queue.lock().await;
126
127 let take_count = max_size.min(queue.len());
128
129 for _ in 0..take_count {
130 if let Some(std::cmp::Reverse(envelope)) = queue.pop() {
131 batch.push(envelope);
132 }
133 }
134 let remaining_queue_len = queue.len();
135 drop(queue);
136
137 if let Some((max_age_ms, event_id, priority)) = batch
138 .iter()
139 .filter_map(|envelope| {
140 envelope
141 .timestamp
142 .elapsed()
143 .ok()
144 .map(|age| (age.as_millis(), envelope.id.as_str(), envelope.priority))
145 })
146 .max_by_key(|(age_ms, _, _)| *age_ms)
147 {
148 if max_age_ms >= SLOW_EVENT_QUEUE_LATENCY_MS {
149 warn!(
150 "Slow agentic event queue delivery: max_age_ms={}, batch_size={}, remaining_queue_len={}, event_id={}, priority={:?}",
151 max_age_ms,
152 batch.len(),
153 remaining_queue_len,
154 event_id,
155 priority
156 );
157 }
158 }
159
160 // Update statistics
161 if !batch.is_empty() {
162 let mut stats = self.stats.lock().await;
163 stats.total_processed += batch.len() as u64;
164 stats.pending_events = remaining_queue_len;
165 }
166
167 batch
168 }
169
170 /// Dequeue a batch using the queue's configured batch size.
171 pub async fn dequeue_configured_batch(&self) -> Vec<EventEnvelope> {

Calls 8

iterMethod · 0.80
dropFunction · 0.50
lenMethod · 0.45
popMethod · 0.45
pushMethod · 0.45
okMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected