mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-05 11:40:04 +00:00
Run QuickInstall reporting using tokio::spawn
So that it is run in concurrent or even in parallel with the `remote_exists`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
43d5a6bdb1
commit
cf87abba16
1 changed files with 26 additions and 20 deletions
|
@ -3,6 +3,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
|
use tokio::task::JoinHandle;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use super::Data;
|
use super::Data;
|
||||||
|
@ -31,7 +32,7 @@ impl super::Fetcher for QuickInstall {
|
||||||
|
|
||||||
async fn check(&self) -> Result<bool, BinstallError> {
|
async fn check(&self) -> Result<bool, BinstallError> {
|
||||||
let url = self.package_url();
|
let url = self.package_url();
|
||||||
self.report().await?;
|
self.report();
|
||||||
info!("Checking for package at: '{url}'");
|
info!("Checking for package at: '{url}'");
|
||||||
remote_exists(Url::parse(&url)?, Method::HEAD).await
|
remote_exists(Url::parse(&url)?, Method::HEAD).await
|
||||||
}
|
}
|
||||||
|
@ -76,26 +77,31 @@ impl QuickInstall {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn report(&self) -> Result<(), BinstallError> {
|
pub fn report(&self) -> JoinHandle<Result<(), BinstallError>> {
|
||||||
if cfg!(debug_assertions) {
|
let stats_url = self.stats_url();
|
||||||
debug!("Not sending quickinstall report in debug mode");
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let url = Url::parse(&self.stats_url())?;
|
tokio::spawn(async move {
|
||||||
debug!("Sending installation report to quickinstall ({url})");
|
if cfg!(debug_assertions) {
|
||||||
|
debug!("Not sending quickinstall report in debug mode");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
reqwest::Client::builder()
|
let url = Url::parse(&stats_url)?;
|
||||||
.user_agent(USER_AGENT)
|
debug!("Sending installation report to quickinstall ({url})");
|
||||||
.build()?
|
|
||||||
.request(Method::HEAD, url.clone())
|
reqwest::Client::builder()
|
||||||
.send()
|
.user_agent(USER_AGENT)
|
||||||
.await
|
.build()?
|
||||||
.map_err(|err| BinstallError::Http {
|
.request(Method::HEAD, url.clone())
|
||||||
method: Method::HEAD,
|
.send()
|
||||||
url,
|
.await
|
||||||
err,
|
.map_err(|err| BinstallError::Http {
|
||||||
})?;
|
method: Method::HEAD,
|
||||||
Ok(())
|
url,
|
||||||
|
err,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue