Do not reset timer for each reported event

This commit is contained in:
Joseph T. Lyons 2024-01-16 18:31:00 -05:00
parent 391a61cdc2
commit 00682b8903

View File

@ -457,20 +457,24 @@ impl Telemetry {
return;
}
if state.flush_events_task.is_none() {
let this = self.clone();
let executor = self.executor.clone();
state.flush_events_task = Some(self.executor.spawn(async move {
executor.timer(FLUSH_DEBOUNCE_INTERVAL).await;
this.flush_events();
}));
}
let signed_in = state.metrics_id.is_some();
state.events_queue.push(EventWrapper { signed_in, event });
dbg!(&state.events_queue.len());
if state.installation_id.is_some() {
if state.events_queue.len() >= MAX_QUEUE_LEN {
drop(state);
self.flush_events();
} else {
let this = self.clone();
let executor = self.executor.clone();
state.flush_events_task = Some(self.executor.spawn(async move {
executor.timer(FLUSH_DEBOUNCE_INTERVAL).await;
this.flush_events();
}));
}
}
}
@ -534,6 +538,7 @@ impl Telemetry {
release_channel: state.release_channel,
events,
};
dbg!("flush", &request_body);
json_bytes.clear();
serde_json::to_writer(&mut json_bytes, &request_body)?;
}