From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 7CCA31FF138 for ; Wed, 04 Feb 2026 16:27:40 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5C47F18526; Wed, 4 Feb 2026 16:28:12 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager 5/5] parallel fetcher: add module documentation Date: Wed, 4 Feb 2026 16:27:23 +0100 Message-ID: <20260204152723.482258-6-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260204152723.482258-1-l.wagner@proxmox.com> References: <20260204152723.482258-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: 1770218781428 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: 22OAMNWAFNX2SIL5JKPMA5L6E6JDOPUG X-Message-ID-Hash: 22OAMNWAFNX2SIL5JKPMA5L6E6JDOPUG 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: Adding a (no-run) doctest for the module level documentation gives users a quick idea on how to use this helper. Signed-off-by: Lukas Wagner --- server/src/parallel_fetcher.rs | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/server/src/parallel_fetcher.rs b/server/src/parallel_fetcher.rs index 57011096..0abd9a50 100644 --- a/server/src/parallel_fetcher.rs +++ b/server/src/parallel_fetcher.rs @@ -1,3 +1,66 @@ +//! Helpers that can be used to parallelize API requests to remotes. +//! +//! ```no_run +//! # use anyhow::Error; +//! # +//! # use pdm_api_types::remotes::{RemoteType, Remote}; +//! # use server::parallel_fetcher::ParallelFetcher; +//! # +//! # #[tokio::main] +//! # async fn main() -> Result<(), Error> { +//! # let remotes: Vec = Vec::new(); +//! # +//! async fn fetch_meaning( +//! _context: (), +//! remote: Remote, +//! node: String, +//! ) -> Result { +//! match remote.ty { +//! RemoteType::Pve => { +//! // Perform the API request here and return some result. +//! Ok(42) +//! }, +//! RemoteType::Pbs => Ok(42), +//! } +//! } +//! +//! // This context can be passed to the function what is executed for every remote node. +//! let context = (); +//! +//! let fetcher = ParallelFetcher::builder(context) +//! .max_connections(10) +//! .max_connections_per_remote(2) +//! .build(); +//! +//! let fetch_result = fetcher +//! .do_for_all_remote_nodes(remotes.into_iter(), fetch_meaning) +//! .await; +//! +//! for remote_outcome in fetch_result { +//! match remote_outcome.nodes() { +//! Ok(node_outcomes) => { +//! for node_outcome in node_outcomes { +//! match node_outcome.data() { +//! Ok(meaning) => assert_eq!(*meaning, 42), +//! Err(err) => +//! log::error!( +//! "failed to retrieve result for node {}", +//! node_outcome.node_name() +//! ), +//! } +//! } +//! } +//! Err(err) => log::error!( +//! "failed to connect to remote {}", +//! remote_outcome.remote() +//! ), +//! } +//! } +//! +//! # Ok(()) +//! # } +//! ``` + use std::fmt::Debug; use std::future::Future; use std::sync::Arc; @@ -14,7 +77,9 @@ use pdm_api_types::remotes::{Remote, RemoteType}; use crate::connection; +/// Maximum number of parallel outgoing API requests. pub const DEFAULT_MAX_CONNECTIONS: usize = 20; +/// Maximum number of parallel outgoing API requests to the *same* remote. pub const DEFAULT_MAX_CONNECTIONS_PER_REMOTE: usize = 5; /// Outcome type produced by [`ParallelFetcher::do_for_all_remotes`] or -- 2.47.3