all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 3/5] parallel fetcher: add builder and make struct members private
Date: Wed,  4 Feb 2026 16:27:21 +0100	[thread overview]
Message-ID: <20260204152723.482258-4-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260204152723.482258-1-l.wagner@proxmox.com>

ParallelFetcher could potentially be used quite often in the PDM
codebase, so it makes sense to make its usage as convenient as possible.
Also, it makes sense to hide its internals as much as possible, so that
we can make future changes without modifying the callers.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 .../tasks/remote_tasks.rs                     |  9 ++-
 server/src/parallel_fetcher.rs                | 58 ++++++++++++++++---
 2 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs b/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs
index c71a0894..93a0d05e 100644
--- a/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs
+++ b/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs
@@ -264,11 +264,10 @@ async fn fetch_remotes(
     remotes: Vec<Remote>,
     cache_state: Arc<State>,
 ) -> (Vec<TaskCacheItem>, NodeFetchSuccessMap) {
-    let fetcher = ParallelFetcher {
-        max_connections: MAX_CONNECTIONS,
-        max_connections_per_remote: CONNECTIONS_PER_PVE_REMOTE,
-        context: cache_state,
-    };
+    let fetcher = ParallelFetcher::builder(cache_state)
+        .max_connections(MAX_CONNECTIONS)
+        .max_connections_per_remote(CONNECTIONS_PER_PVE_REMOTE)
+        .build();
 
     let fetch_results = fetcher
         .do_for_all_remote_nodes(remotes.into_iter(), fetch_tasks_from_single_node)
diff --git a/server/src/parallel_fetcher.rs b/server/src/parallel_fetcher.rs
index f07a2de3..1eded293 100644
--- a/server/src/parallel_fetcher.rs
+++ b/server/src/parallel_fetcher.rs
@@ -19,9 +19,9 @@ pub const DEFAULT_MAX_CONNECTIONS: usize = 20;
 pub const DEFAULT_MAX_CONNECTIONS_PER_REMOTE: usize = 5;
 
 pub struct ParallelFetcher<C> {
-    pub max_connections: usize,
-    pub max_connections_per_remote: usize,
-    pub context: C,
+    max_connections: usize,
+    max_connections_per_remote: usize,
+    context: C,
 }
 
 pub struct FetchResults<T> {
@@ -59,15 +59,59 @@ pub struct NodeResults<T> {
     pub api_response_time: Duration,
 }
 
-impl<C: Clone + Send + 'static> ParallelFetcher<C> {
-    pub fn new(context: C) -> Self {
+/// Builder for the [`ParallelFetcher`] struct.
+pub struct ParallelFetcherBuilder<C> {
+    max_connections: Option<usize>,
+    max_connections_per_remote: Option<usize>,
+    context: C,
+}
+
+impl<C> ParallelFetcherBuilder<C> {
+    fn new(context: C) -> Self {
         Self {
-            max_connections: DEFAULT_MAX_CONNECTIONS,
-            max_connections_per_remote: DEFAULT_MAX_CONNECTIONS_PER_REMOTE,
             context,
+            max_connections: None,
+            max_connections_per_remote: None,
         }
     }
 
+    /// Set the maximum number of parallel connections.
+    pub fn max_connections(mut self, limit: usize) -> Self {
+        self.max_connections = Some(limit);
+        self
+    }
+
+    /// Set the maximum number of parallel connections per remote.
+    ///
+    /// This only really affects PVE remotes with multiple cluster members.
+    pub fn max_connections_per_remote(mut self, limit: usize) -> Self {
+        self.max_connections_per_remote = Some(limit);
+        self
+    }
+
+    /// Build the [`ParallelFetcher`] instance.
+    pub fn build(self) -> ParallelFetcher<C> {
+        ParallelFetcher {
+            max_connections: self.max_connections.unwrap_or(DEFAULT_MAX_CONNECTIONS),
+            max_connections_per_remote: self
+                .max_connections_per_remote
+                .unwrap_or(DEFAULT_MAX_CONNECTIONS_PER_REMOTE),
+            context: self.context,
+        }
+    }
+}
+
+impl<C: Clone + Send + 'static> ParallelFetcher<C> {
+    /// Create a [`ParallelFetcher`] with default settings.
+    pub fn new(context: C) -> Self {
+        Self::builder(context).build()
+    }
+
+    /// Create the builder for constructing a [`ParallelFetcher`] with custom settings.
+    pub fn builder(context: C) -> ParallelFetcherBuilder<C> {
+        ParallelFetcherBuilder::new(context)
+    }
+
     pub async fn do_for_all_remote_nodes<A, F, T, Ft>(self, remotes: A, func: F) -> FetchResults<T>
     where
         A: Iterator<Item = Remote>,
-- 
2.47.3





  parent reply	other threads:[~2026-02-04 15:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04 15:27 [PATCH datacenter-manager 0/5] improvements for ParallelFetcher Lukas Wagner
2026-02-04 15:27 ` [PATCH datacenter-manager 1/5] parallel fetcher: clean up imports Lukas Wagner
2026-02-04 15:27 ` [PATCH datacenter-manager 2/5] parallel fetcher: make sure to inherit log context Lukas Wagner
2026-02-04 15:27 ` Lukas Wagner [this message]
2026-02-04 15:27 ` [PATCH datacenter-manager 4/5] parallel fetcher: improve result type ergonomics Lukas Wagner
2026-02-04 15:27 ` [PATCH datacenter-manager 5/5] parallel fetcher: add module documentation Lukas Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260204152723.482258-4-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal