forked from janek/mostr
1
0
Fork 0

fix: flush after backtrack

This commit is contained in:
xeruf 2024-08-06 17:57:01 +03:00
parent db4f9ee8cb
commit b5b57b7ac9
1 changed files with 5 additions and 7 deletions

View File

@ -35,15 +35,13 @@ struct EventSender {
impl EventSender { impl EventSender {
fn submit(&self, event_builder: EventBuilder) -> Result<Event> { fn submit(&self, event_builder: EventBuilder) -> Result<Event> {
{ {
// Flush if oldest event older than a minute // Always flush if oldest event older than a minute or newer than now
let borrow = self.queue.borrow(); let borrow = self.queue.borrow();
if let Some(event) = borrow.first() { let min = Timestamp::now().sub(60u64);
let old = event.created_at < Timestamp::now().sub(60u64); if borrow.iter().any(|e| e.created_at < min || e.created_at > Timestamp::now()) {
drop(borrow); drop(borrow);
if old { debug!("Flushing event queue because it is older than a minute");
debug!("Flushing event queue because it is older than a minute"); self.force_flush();
self.force_flush();
}
} }
} }
let mut queue = self.queue.borrow_mut(); let mut queue = self.queue.borrow_mut();