Add debounce time back to telemetry queue
This commit is contained in:
parent
5437c8041a
commit
366d386dbb
1 changed files with 16 additions and 0 deletions
|
@ -28,6 +28,7 @@ struct TelemetryState {
|
||||||
app_metadata: AppMetadata,
|
app_metadata: AppMetadata,
|
||||||
architecture: &'static str,
|
architecture: &'static str,
|
||||||
clickhouse_events_queue: Vec<ClickhouseEventWrapper>,
|
clickhouse_events_queue: Vec<ClickhouseEventWrapper>,
|
||||||
|
flush_clickhouse_events_task: Option<Task<()>>,
|
||||||
log_file: Option<NamedTempFile>,
|
log_file: Option<NamedTempFile>,
|
||||||
is_staff: Option<bool>,
|
is_staff: Option<bool>,
|
||||||
first_event_datetime: Option<DateTime<Utc>>,
|
first_event_datetime: Option<DateTime<Utc>>,
|
||||||
|
@ -124,6 +125,12 @@ const MAX_QUEUE_LEN: usize = 1;
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
const MAX_QUEUE_LEN: usize = 50;
|
const MAX_QUEUE_LEN: usize = 50;
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1);
|
||||||
|
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(60 * 5);
|
||||||
|
|
||||||
impl Telemetry {
|
impl Telemetry {
|
||||||
pub fn new(client: Arc<dyn HttpClient>, cx: &mut AppContext) -> Arc<Self> {
|
pub fn new(client: Arc<dyn HttpClient>, cx: &mut AppContext) -> Arc<Self> {
|
||||||
let release_channel = if cx.has_global::<ReleaseChannel>() {
|
let release_channel = if cx.has_global::<ReleaseChannel>() {
|
||||||
|
@ -144,6 +151,7 @@ impl Telemetry {
|
||||||
metrics_id: None,
|
metrics_id: None,
|
||||||
session_id: None,
|
session_id: None,
|
||||||
clickhouse_events_queue: Default::default(),
|
clickhouse_events_queue: Default::default(),
|
||||||
|
flush_clickhouse_events_task: Default::default(),
|
||||||
log_file: None,
|
log_file: None,
|
||||||
is_staff: None,
|
is_staff: None,
|
||||||
first_event_datetime: None,
|
first_event_datetime: None,
|
||||||
|
@ -424,6 +432,13 @@ impl Telemetry {
|
||||||
if immediate_flush || state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN {
|
if immediate_flush || state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN {
|
||||||
drop(state);
|
drop(state);
|
||||||
self.flush_clickhouse_events();
|
self.flush_clickhouse_events();
|
||||||
|
} else {
|
||||||
|
let this = self.clone();
|
||||||
|
let executor = self.executor.clone();
|
||||||
|
state.flush_clickhouse_events_task = Some(self.executor.spawn(async move {
|
||||||
|
executor.timer(DEBOUNCE_INTERVAL).await;
|
||||||
|
this.flush_clickhouse_events();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,6 +459,7 @@ impl Telemetry {
|
||||||
let mut state = self.state.lock();
|
let mut state = self.state.lock();
|
||||||
state.first_event_datetime = None;
|
state.first_event_datetime = None;
|
||||||
let mut events = mem::take(&mut state.clickhouse_events_queue);
|
let mut events = mem::take(&mut state.clickhouse_events_queue);
|
||||||
|
state.flush_clickhouse_events_task.take();
|
||||||
drop(state);
|
drop(state);
|
||||||
|
|
||||||
let this = self.clone();
|
let this = self.clone();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue