-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, `ChunkOptions` was implemented as a trait, but we realized it makes more sense to have it be a struct, instead. Now, as a struct, we also have `ChunkOptions` store the `ChunkServerOptions`, which will eventually allow us to simplify some API's, since we can take `ChunkOptions` only, rather than `DIFUpload` and `ChunkServerOptions` for methods such as `upload_difs_chunked`.
- Loading branch information
1 parent
60dbdde
commit b42e559
Showing
3 changed files
with
92 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,63 @@ | ||
use std::time::Duration; | ||
use std::{cmp, time::Duration}; | ||
|
||
/// A trait representing options for chunk uploads. | ||
pub trait ChunkOptions { | ||
/// Determines whether we need to strip debug_ids from the requests. | ||
/// When this function returns `true`, the caller is responsible for stripping | ||
/// the debug_ids from the requests, to maintain backwards compatibility with | ||
/// older Sentry servers. | ||
fn should_strip_debug_ids(&self) -> bool; | ||
use crate::api::ChunkServerOptions; | ||
|
||
/// Returns the organization that we are uploading to. | ||
fn org(&self) -> &str; | ||
/// A struct representing options for chunk uploads. | ||
pub struct ChunkOptions<'a> { | ||
server_options: ChunkServerOptions, | ||
org: &'a str, | ||
project: &'a str, | ||
|
||
/// Returns the project that we are uploading to. | ||
fn project(&self) -> &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> ChunkOptions<'a> { | ||
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 with_max_wait(mut self, max_wait: Duration) -> Self { | ||
self.max_wait = max_wait; | ||
self | ||
} | ||
|
||
pub fn should_strip_debug_ids(&self) -> bool { | ||
self.server_options.should_strip_debug_ids() | ||
} | ||
|
||
pub fn org(&self) -> &str { | ||
self.org | ||
} | ||
|
||
pub fn project(&self) -> &str { | ||
self.project | ||
} | ||
|
||
pub fn should_wait(&self) -> bool { | ||
!self.max_wait().is_zero() | ||
} | ||
|
||
/// Returns whether we should wait for assembling to complete. | ||
fn should_wait(&self) -> bool; | ||
pub 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)), | ||
} | ||
} | ||
|
||
/// Returns the maximum wait time for the upload to complete. | ||
fn max_wait(&self) -> Duration; | ||
pub fn server_options(&self) -> &ChunkServerOptions { | ||
&self.server_options | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters