Flush the batch buffer and send all events.
(&self)
| 458 | |
| 459 | /// Flush the batch buffer and send all events. |
| 460 | pub async fn flush_batch(&self) { |
| 461 | let events = { |
| 462 | let mut buffer = write_or_recover(&self.batch_buffer); |
| 463 | if buffer.is_empty() { |
| 464 | return; |
| 465 | } |
| 466 | std::mem::take(&mut *buffer) |
| 467 | }; |
| 468 | |
| 469 | if !events.is_empty() { |
| 470 | let now = std::time::SystemTime::now() |
| 471 | .duration_since(std::time::UNIX_EPOCH) |
| 472 | .unwrap() |
| 473 | .as_millis() as u64; |
| 474 | self.last_batch_flush.store(now, Ordering::Relaxed); |
| 475 | |
| 476 | match self.client.send_batch(events).await { |
| 477 | Ok(_) => { |
| 478 | debug!("Batch sent successfully"); |
| 479 | } |
| 480 | Err(e) => { |
| 481 | warn!("Batch send failed: {}", e); |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | /// Check if batch timeout has expired and flush if needed. |
| 488 | pub async fn check_batch_timeout(&self) { |
no test coverage detected