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

feat: modify Downloader config through Blobs builder #75

Merged
Merged
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
28 changes: 25 additions & 3 deletions src/net_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
use tracing::debug;

use crate::{
downloader::Downloader,
downloader::{ConcurrencyLimits, Downloader, RetryConfig},
provider::EventSender,
store::GcConfig,
util::{
Expand Down Expand Up @@ -148,6 +148,8 @@ pub struct Builder<S> {
store: S,
events: Option<EventSender>,
rt: Option<LocalPoolHandle>,
concurrency_limits: Option<ConcurrencyLimits>,
retry_config: Option<RetryConfig>,
}

impl<S: crate::store::Store> Builder<S> {
Expand All @@ -157,20 +159,38 @@ impl<S: crate::store::Store> Builder<S> {
self
}

/// Set a custom `LocalPoolHandle` to use.
/// Set a custom [`LocalPoolHandle`] to use.
pub fn local_pool(mut self, rt: LocalPoolHandle) -> Self {
self.rt = Some(rt);
self
}

/// Set custom [`ConcurrencyLimits`] to use.
pub fn concurrency_limits(mut self, concurrency_limits: ConcurrencyLimits) -> Self {
self.concurrency_limits = Some(concurrency_limits);
self
}

/// Set a custom [`RetryConfig`] to use.
pub fn retry_config(mut self, retry_config: RetryConfig) -> Self {
self.retry_config = Some(retry_config);
self
}

/// Build the Blobs protocol handler.
/// You need to provide a the endpoint.
pub fn build(self, endpoint: &Endpoint) -> Blobs<S> {
let rt = self
.rt
.map(Rt::Handle)
.unwrap_or_else(|| Rt::Owned(LocalPool::default()));
let downloader = Downloader::new(self.store.clone(), endpoint.clone(), rt.clone());
let downloader = Downloader::with_config(
self.store.clone(),
endpoint.clone(),
rt.clone(),
self.concurrency_limits.unwrap_or_default(),
self.retry_config.unwrap_or_default(),
);
Blobs::new(
self.store,
rt,
Expand All @@ -188,6 +208,8 @@ impl<S> Blobs<S> {
store,
events: None,
rt: None,
concurrency_limits: None,
retry_config: None,
}
}
}
Expand Down
Loading