Skip to content

Commit

Permalink
ref(proguard): Use existing chunked upload logic
Browse files Browse the repository at this point in the history
Use the existing chunked upload logic (already used for DIFs) when chunked-uploading Proguard mappings.

Closes #2195, #2196
  • Loading branch information
szokeasaurusrex committed Dec 16, 2024
1 parent aa015da commit ceef75b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/utils/chunks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod upload;

pub use options::ChunkOptions;
pub use types::{Assemblable, Chunked, MissingObjectsInfo};
pub use upload::{upload_chunked_objects, ChunkOptions};
pub use upload::upload_chunked_objects;

use std::sync::Arc;
use std::time::Duration;
Expand Down
68 changes: 2 additions & 66 deletions src/utils/chunks/upload.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use std::fmt::Display;
use std::time::{Duration, Instant};
use std::{cmp, thread};
use std::thread;
use std::time::Instant;

use anyhow::Result;
use indicatif::ProgressStyle;
Expand Down Expand Up @@ -324,67 +324,3 @@ fn render_detail(detail: Option<&str>, fallback: Option<&str>) {
}
}
}

/// A struct representing options for chunk uploads. This implementation
/// of `ChunkOptions` should be general enough to be used for any chunk upload.
pub struct GenericChunkOptions<'a> {
server_options: ChunkServerOptions,
org: &'a str,
project: &'a str,

/// The maximum wait time for the upload to complete.
/// If set to zero, we do not wait for the upload to complete.
/// If the server_options.max_wait is set to a smaller nonzero value,
/// we use that value instead.
max_wait: Duration,
}

impl<'a> GenericChunkOptions<'a> {
/// Create a new `GenericChunkOptions` instance, with the provided server options,
/// organization, and project, and no wait time for the upload to complete.
pub fn new(server_options: ChunkServerOptions, org: &'a str, project: &'a str) -> Self {
Self {
server_options,
org,
project,
max_wait: Duration::ZERO,
}
}

/// Set the maximum wait time for the assembly to complete.
pub fn set_max_wait(&mut self, max_wait: Duration) {
self.max_wait = max_wait;
}
}

impl ChunkOptions for GenericChunkOptions<'_> {
fn should_strip_debug_ids(&self) -> bool {
self.server_options.should_strip_debug_ids()
}

fn org(&self) -> &str {
self.org
}

fn project(&self) -> &str {
self.project
}

fn should_wait(&self) -> bool {
!self.max_wait().is_zero()
}

fn max_wait(&self) -> Duration {
// If the server specifies a max wait time (indicated by a nonzero value),
// we use the minimum of the user-specified max wait time and the server's
// max wait time.
match self.server_options.max_wait {
0 => self.max_wait,
server_max_wait => cmp::min(self.max_wait, Duration::from_secs(server_max_wait)),
}
}

fn server_options(&self) -> &ChunkServerOptions {
&self.server_options
}
}
9 changes: 4 additions & 5 deletions src/utils/proguard/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::time::Duration;
use anyhow::Result;

use crate::api::ChunkServerOptions;
use crate::utils::chunks::GenericChunkOptions;
use crate::utils::chunks::{ChunkOptions, Chunked};
use crate::utils::chunks::{upload_chunked_objects, ChunkOptions, Chunked};
use crate::utils::proguard::ProguardMapping;

/// How long to wait for the server to assemble the mappings before giving up.
Expand All @@ -32,10 +31,10 @@ pub fn chunk_upload(
.map(|mapping| Chunked::from(mapping, chunk_upload_options.chunk_size as usize))
.collect::<Result<Vec<_>>>()?;

let mut options = GenericChunkOptions::new(chunk_upload_options, org, project);
options.set_max_wait(ASSEMBLE_POLL_TIMEOUT);
let options =
ChunkOptions::new(chunk_upload_options, org, project).with_max_wait(ASSEMBLE_POLL_TIMEOUT);

let (_, has_processing_errors) = options.upload_chunked_objects(&chunked_mappings)?;
let (_, has_processing_errors) = upload_chunked_objects(&chunked_mappings, options)?;

if has_processing_errors {
Err(anyhow::anyhow!("Some symbols did not process correctly"))
Expand Down

0 comments on commit ceef75b

Please sign in to comment.