Skip to content

Commit

Permalink
ref(dif): Genericize poll_assemble
Browse files Browse the repository at this point in the history
This requires adding `should_wait` and `max_wait` functions to the `ChunkOptions` trait.
  • Loading branch information
szokeasaurusrex committed Dec 6, 2024
1 parent 225d304 commit 1d5d593
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
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
}
}

0 comments on commit 1d5d593

Please sign in to comment.