Skip to content

Commit

Permalink
fix: put call to report launch success on bg thread. (#72)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bryanoltman committed Aug 17, 2023
1 parent 7417429 commit 53072a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 4 additions & 0 deletions library/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 2 additions & 8 deletions library/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
14 changes: 9 additions & 5 deletions library/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
}

Expand Down

0 comments on commit 53072a9

Please sign in to comment.