Skip to content

Commit c99baf7

Browse files
committed
rust: restructure GitHub artifact downloading
Before, we initiated the HTTP requests all at once. On slow network connections or machines this resulted in timeouts due to some requests not being serviced in a timely manner. This commit refactors the code so requests are issued when their future is waited on and not before. This should result in more reliable fetching of artifacts.
1 parent 468d089 commit c99baf7

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2018"
66

77
[dependencies]
88
anyhow = "1"
9+
bytes = "1.1"
910
clap = "2"
1011
duct = "0"
1112
futures = "0"

src/github.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use {
66
anyhow::{anyhow, Result},
77
clap::ArgMatches,
88
futures::StreamExt,
9-
octocrab::OctocrabBuilder,
9+
octocrab::{Octocrab, OctocrabBuilder},
1010
once_cell::sync::Lazy,
1111
serde::Deserialize,
1212
std::{
@@ -70,6 +70,15 @@ struct Artifacts {
7070
total_count: u64,
7171
}
7272

73+
async fn fetch_artifact(client: &Octocrab, artifact: Artifact) -> Result<bytes::Bytes> {
74+
println!("downloading {}", artifact.name);
75+
let res = client
76+
.execute(client.request_builder(&artifact.archive_download_url, reqwest::Method::GET))
77+
.await?;
78+
79+
Ok(res.bytes().await?)
80+
}
81+
7382
pub async fn command_fetch_release_distributions(args: &ArgMatches<'_>) -> Result<()> {
7483
let dest_dir = PathBuf::from(args.value_of("dest").expect("dest directory should be set"));
7584
let org = args
@@ -134,14 +143,7 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches<'_>) -> Resul
134143
continue;
135144
}
136145

137-
println!("downloading {}", artifact.name);
138-
let res = client
139-
.execute(
140-
client.request_builder(artifact.archive_download_url, reqwest::Method::GET),
141-
)
142-
.await?;
143-
144-
fs.push(res.bytes());
146+
fs.push(fetch_artifact(&client, artifact));
145147
}
146148
}
147149

0 commit comments

Comments
 (0)