From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 18CEE1FF13F for ; Thu, 29 Jan 2026 14:44:09 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A773B5475; Thu, 29 Jan 2026 14:44:32 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [RFC datacenter-manager 2/6] parallel fetcher: allow to use custom client factory Date: Thu, 29 Jan 2026 14:44:14 +0100 Message-ID: <20260129134418.307552-4-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260129134418.307552-1-l.wagner@proxmox.com> References: <20260129134418.307552-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1769694199869 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.037 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: EWAZ4HB2JBNCTWSZA56JPHCFAVQJHHHK X-Message-ID-Hash: EWAZ4HB2JBNCTWSZA56JPHCFAVQJHHHK X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This will become useful later when the actual client factory is a custom mocked one that we use for tests. Signed-off-by: Lukas Wagner --- .../tasks/remote_tasks.rs | 2 ++ server/src/parallel_fetcher.rs | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 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..7ce37631 100644 --- a/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs +++ b/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs @@ -264,10 +264,12 @@ async fn fetch_remotes( remotes: Vec, cache_state: Arc, ) -> (Vec, NodeFetchSuccessMap) { + // FIXME: Use constructor or builder pattern here... let fetcher = ParallelFetcher { max_connections: MAX_CONNECTIONS, max_connections_per_remote: CONNECTIONS_PER_PVE_REMOTE, context: cache_state, + client_factory: connection::client_factory(), }; let fetch_results = fetcher diff --git a/server/src/parallel_fetcher.rs b/server/src/parallel_fetcher.rs index 58ca1f55..f123460d 100644 --- a/server/src/parallel_fetcher.rs +++ b/server/src/parallel_fetcher.rs @@ -14,15 +14,18 @@ use tokio::{ task::JoinSet, }; -use crate::connection; +use crate::connection::{self, ClientFactory}; pub const DEFAULT_MAX_CONNECTIONS: usize = 20; pub const DEFAULT_MAX_CONNECTIONS_PER_REMOTE: usize = 5; +/// FIXME: Builder pattern, make fields private pub struct ParallelFetcher { pub max_connections: usize, pub max_connections_per_remote: usize, pub context: C, + + pub client_factory: Arc, } pub struct FetchResults { @@ -66,6 +69,20 @@ impl ParallelFetcher { max_connections: DEFAULT_MAX_CONNECTIONS, max_connections_per_remote: DEFAULT_MAX_CONNECTIONS_PER_REMOTE, context, + client_factory: connection::client_factory(), + } + } + + // TODO: maybe add actual builder pattern. + pub fn new_with_client_factory( + context: C, + client_factory: Arc, + ) -> Self { + Self { + max_connections: DEFAULT_MAX_CONNECTIONS, + max_connections_per_remote: DEFAULT_MAX_CONNECTIONS_PER_REMOTE, + context, + client_factory, } } @@ -82,6 +99,7 @@ impl ParallelFetcher { for remote in remotes { let semaphore = Arc::clone(&total_connections_semaphore); + let client_factory = Arc::clone(&self.client_factory); let f = func.clone(); @@ -91,6 +109,7 @@ impl ParallelFetcher { semaphore, f, self.max_connections_per_remote, + client_factory, )); } @@ -116,6 +135,7 @@ impl ParallelFetcher { semaphore: Arc, func: F, max_connections_per_remote: usize, + client_factory: Arc, ) -> (String, Result, Error>) where F: Fn(C, Remote, String) -> Ft + Clone + Send + 'static, @@ -132,7 +152,7 @@ impl ParallelFetcher { let remote_clone = remote.clone(); let nodes = match async move { - let client = connection::make_pve_client(&remote_clone)?; + let client = client_factory.make_pve_client(&remote_clone)?; let nodes = client.list_nodes().await?; Ok::, Error>(nodes) -- 2.47.3