From 53072a91281922025155477ea2ba009f690c8eed Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Thu, 17 Aug 2023 14:55:26 -0400 Subject: [PATCH] fix: put call to report launch success on bg thread. (#72) * fix: use non-blocking http client when reporting launch success * Make patch install report request on bg thread * Pass client_id instead of state * Convert client_id from &str to String --- library/src/cache.rs | 4 ++++ library/src/network.rs | 10 ++-------- library/src/updater.rs | 14 +++++++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/library/src/cache.rs b/library/src/cache.rs index ca03937..5398d1e 100644 --- a/library/src/cache.rs +++ b/library/src/cache.rs @@ -71,6 +71,10 @@ impl UpdaterState { slots: Vec::new(), } } + + pub fn client_id_or_default(&self) -> String { + self.client_id.clone().unwrap_or("".to_string()) + } } fn is_file_not_found(error: &anyhow::Error) -> bool { diff --git a/library/src/network.rs b/library/src/network.rs index b713238..b1f854e 100644 --- a/library/src/network.rs +++ b/library/src/network.rs @@ -291,19 +291,13 @@ pub fn send_patch_check_request( pub fn report_successful_patch_install( config: &UpdateConfig, - state: &UpdaterState, + client_id: String, patch_number: usize, ) -> anyhow::Result<()> { - let client_id = state - .client_id - .clone() - .unwrap_or("".to_string()) - .to_string(); - let event = PatchInstallEvent::new( config.app_id.clone(), current_arch().to_string(), - client_id.to_string(), + client_id, patch_number, current_platform().to_string(), config.release_version.clone(), diff --git a/library/src/updater.rs b/library/src/updater.rs index 5a79943..9df3b40 100644 --- a/library/src/updater.rs +++ b/library/src/updater.rs @@ -384,11 +384,15 @@ pub fn report_launch_success() -> anyhow::Result<()> { // Ignore the error here, we'll try to activate the next best patch // even if we fail to mark this one as good. if state.mark_patch_as_good(patch.number).is_ok() { - let report_result = - report_successful_patch_install(&config, &state, patch.number); - if let Err(err) = report_result { - error!("Failed to report successful patch install: {:?}", err); - } + let config_copy = config.clone(); + let client_id = state.client_id_or_default(); + std::thread::spawn(move || { + let report_result = + report_successful_patch_install(&config_copy, client_id, patch.number); + if let Err(err) = report_result { + error!("Failed to report successful patch install: {:?}", err); + } + }); } }