Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
9 changes: 6 additions & 3 deletions qcs-api-client-common/src/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ pub use ::backoff::*;

/// Create a default [`ExponentialBackoff`] for use with QCS.
///
/// This backoff will retry for up to 5 minutes, with a maximum interval of 30 seconds and some
/// randomized jitter.
/// This backoff will retry for up to 5 minutes. The initial interval is 30 seconds,
/// and the backoff will double the interval each time it is used, up to the maximum
/// interval of 2 minutes.
#[allow(clippy::module_name_repetitions)]
#[must_use]
pub fn default_backoff() -> ExponentialBackoff {
ExponentialBackoffBuilder::new()
.with_max_elapsed_time(Some(Duration::from_secs(300)))
.with_max_interval(Duration::from_secs(30))
.with_initial_interval(Duration::from_secs(30))
.with_max_interval(Duration::from_secs(120))
.with_multiplier(2.0)
.build()
}

Expand Down
10 changes: 8 additions & 2 deletions qcs-api-client-grpc/src/tonic/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ pub fn parse_uri(s: &str) -> Result<Uri, Error<TokenError>> {
s.parse().map_err(Error::from)
}

/// Get an [`Endpoint`] for the given [`Uri`]
/// Get an [`Endpoint`] for the given [`Uri`] with default settings.
/// This endpoint will default to using a 2 minute timeout, and will
/// keep the connection alive while idle, with a 60 second keep-alive
/// interval.
#[allow(clippy::missing_panics_doc)]
pub fn get_endpoint(uri: Uri) -> Endpoint {
Channel::builder(uri)
Expand All @@ -351,9 +354,12 @@ pub fn get_endpoint(uri: Uri) -> Endpoint {
.expect("user agent string should be valid")
.tls_config(ClientTlsConfig::new().with_enabled_roots())
.expect("tls setup should succeed")
.keep_alive_while_idle(true)
.http2_keep_alive_interval(Duration::from_secs(60))
.timeout(Duration::from_secs(120))
}

/// Get an [`Endpoint`] for the given [`Uri`] and timeout.
/// Get an [`Endpoint`] for the given [`Uri`] and custom timeout duration.
pub fn get_endpoint_with_timeout(uri: Uri, timeout: Option<Duration>) -> Endpoint {
if let Some(duration) = timeout {
get_endpoint(uri).timeout(duration)
Expand Down