From: Lukas Wagner <l.wagner@proxmox.com>
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 [thread overview]
Message-ID: <20260129134418.307552-4-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260129134418.307552-1-l.wagner@proxmox.com>
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 <l.wagner@proxmox.com>
---
.../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<Remote>,
cache_state: Arc<State>,
) -> (Vec<TaskCacheItem>, 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<C> {
pub max_connections: usize,
pub max_connections_per_remote: usize,
pub context: C,
+
+ pub client_factory: Arc<dyn ClientFactory + Send + Sync>,
}
pub struct FetchResults<T> {
@@ -66,6 +69,20 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
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<dyn ClientFactory + Send + Sync>,
+ ) -> Self {
+ Self {
+ max_connections: DEFAULT_MAX_CONNECTIONS,
+ max_connections_per_remote: DEFAULT_MAX_CONNECTIONS_PER_REMOTE,
+ context,
+ client_factory,
}
}
@@ -82,6 +99,7 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
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<C: Clone + Send + 'static> ParallelFetcher<C> {
semaphore,
f,
self.max_connections_per_remote,
+ client_factory,
));
}
@@ -116,6 +135,7 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
semaphore: Arc<Semaphore>,
func: F,
max_connections_per_remote: usize,
+ client_factory: Arc<dyn ClientFactory + Send + Sync>,
) -> (String, Result<RemoteResult<T>, Error>)
where
F: Fn(C, Remote, String) -> Ft + Clone + Send + 'static,
@@ -132,7 +152,7 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
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::<Vec<ClusterNodeIndexResponse>, Error>(nodes)
--
2.47.3
next prev parent reply other threads:[~2026-01-29 13:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-29 13:44 [RFC datacenter-manager/proxmox 0/7] inject application context via rpcenv for easier integration testing Lukas Wagner
2026-01-29 13:44 ` [RFC proxmox 1/1] router: rpc environment: allow to provide a application-specific context handle via rpcenv Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 1/6] connection: store client factory in an Arc and add public getter Lukas Wagner
2026-01-29 13:44 ` Lukas Wagner [this message]
2026-01-29 13:44 ` [RFC datacenter-manager 3/6] introduce PdmApplication struct and inject it during API server startup Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 4/6] remote updates: use PdmApplication object to derive paths, permissions and client factory Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 5/6] tests: add captured responses for integration tests Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 6/6] tests: add basic integration tests for the remote updates API Lukas Wagner
2026-02-03 11:02 ` [RFC datacenter-manager/proxmox 0/7] inject application context via rpcenv for easier integration testing Robert Obkircher
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=20260129134418.307552-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox