Skip to content

Commit

Permalink
refactor(runner): use async reqwest
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Nov 24, 2023
1 parent 1999672 commit 92bb265
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lazy_static = "1.4.0"
log = "0.4.20"
rand = "0.8.5"
regex = "1.10.2"
reqwest = { version = "0.11.22", features = ["json", "stream", "blocking"] }
reqwest = { version = "0.11.22", features = ["json", "stream"] }
reqwest-middleware = "0.2.4"
reqwest-retry = "0.3.0"
serde = { version = "1.0.192", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub async fn run() -> Result<()> {
let config = Config::try_from(args)?;
show_banner();
debug!("config: {:#?}", config);
let run_data = runner::run(&config)?;
let run_data = runner::run(&config).await?;
if !config.skip_upload {
uploader::upload(&config, &run_data).await?;
}
Expand Down
6 changes: 4 additions & 2 deletions src/runner/helpers/download_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::path::Path;

use url::Url;

pub fn download_file(url: &Url, path: &Path) -> Result<()> {
let response = reqwest::blocking::get(url.clone())
pub async fn download_file(url: &Url, path: &Path) -> Result<()> {
let response = reqwest::get(url.clone())
.await
.map_err(|e| anyhow!("Failed to download file: {}", e))?;
if !response.status().is_success() {
bail!("Failed to download file: {}", response.status());
Expand All @@ -13,6 +14,7 @@ pub fn download_file(url: &Url, path: &Path) -> Result<()> {
.map_err(|e| anyhow!("Failed to create file: {}, {}", path.display(), e))?;
let content = response
.bytes()
.await
.map_err(|e| anyhow!("Failed to read response: {}", e))?;
std::io::copy(&mut content.as_ref(), &mut file).map_err(|e| {
anyhow!(
Expand Down
4 changes: 2 additions & 2 deletions src/runner/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub struct RunData {
pub profile_folder: PathBuf,
}

pub fn run(config: &Config) -> Result<RunData> {
pub async fn run(config: &Config) -> Result<RunData> {
if !config.skip_setup {
let system_info = check_system()?;
setup(&system_info)?;
setup(&system_info).await?;
}
//TODO: add valgrind version check
let profile_folder = create_profile_folder()?;
Expand Down
4 changes: 2 additions & 2 deletions src/runner/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use crate::prelude::*;

const VALGRIND_CODSPEED_VERSION: &str = "3.21.0-0codspeed1";

pub fn setup(system_info: &SystemInfo) -> Result<()> {
pub async fn setup(system_info: &SystemInfo) -> Result<()> {
let valgrind_deb_url = format!("https://github.com/CodSpeedHQ/valgrind-codspeed/releases/download/{}/valgrind_{}_ubuntu-{}_amd64.deb", VALGRIND_CODSPEED_VERSION, VALGRIND_CODSPEED_VERSION, system_info.os_version);
let deb_path = env::temp_dir().join("valgrind-codspeed.deb");
download_file(&Url::parse(valgrind_deb_url.as_str()).unwrap(), &deb_path)?;
download_file(&Url::parse(valgrind_deb_url.as_str()).unwrap(), &deb_path).await?;
let update_status = Command::new("apt")
.args(["update"])
.status()
Expand Down

0 comments on commit 92bb265

Please sign in to comment.