Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(dif): Genericize poll_assemble #2300

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/utils/chunks/upload.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

/// A trait representing options for chunk uploads.
pub trait ChunkOptions {
/// Determines whether we need to strip debug_ids from the requests.
Expand All @@ -11,4 +13,10 @@ pub trait ChunkOptions {

/// Returns the project that we are uploading to.
fn project(&self) -> &str;

/// Returns whether we should wait for assembling to complete.
fn should_wait(&self) -> bool;

/// Returns the maximum wait time for the upload to complete.
fn max_wait(&self) -> Duration;
}
20 changes: 14 additions & 6 deletions src/utils/dif_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ fn render_detail(detail: &Option<String>, fallback: Option<&str>) {
/// missing chunks in the assemble response, this likely indicates a bug in the server.
fn poll_assemble<T>(
chunked_objects: &[&Chunked<T>],
options: &DifUpload,
options: &impl ChunkOptions,
) -> Result<(Vec<DebugInfoFile>, bool)>
where
T: Display + Assemblable,
Expand All @@ -1392,14 +1392,14 @@ where
let assemble_start = Instant::now();

let mut request: AssembleDifsRequest<'_> = chunked_objects.iter().copied().collect();
if !options.pdbs_allowed {
if options.should_strip_debug_ids() {
request.strip_debug_ids();
}

let response = loop {
let response =
api.authenticated()?
.assemble_difs(&options.org, &options.project, &request)?;
.assemble_difs(options.org(), options.project(), &request)?;

let chunks_missing = response
.values()
Expand All @@ -1415,11 +1415,11 @@ where
// Poll until there is a response, unless the user has specified to skip polling. In
// that case, we return the potentially partial response from the server. This might
// still contain a cached error.
if !options.wait {
if !options.should_wait() {
break response;
}

if assemble_start.elapsed() > options.max_wait {
if assemble_start.elapsed() > options.max_wait() {
break response;
}

Expand All @@ -1446,7 +1446,7 @@ where

let (errors, mut successes): (Vec<_>, _) = response
.into_iter()
.partition(|(_, r)| r.state.is_err() || options.wait && r.state.is_pending());
.partition(|(_, r)| r.state.is_err() || options.should_wait() && r.state.is_pending());

// Print a summary of all successes first, so that errors show up at the
// bottom for the user
Expand Down Expand Up @@ -2108,4 +2108,12 @@ impl ChunkOptions for DifUpload {
fn project(&self) -> &str {
&self.project
}

fn should_wait(&self) -> bool {
self.wait
}

fn max_wait(&self) -> Duration {
self.max_wait
}
}
Loading