public inbox for pdm-devel@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 2/5] parallel fetcher: make sure to inherit log context
Date: Wed,  4 Feb 2026 16:27:20 +0100	[thread overview]
Message-ID: <20260204152723.482258-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260204152723.482258-1-l.wagner@proxmox.com>

If ParallelFetcher is used in a worker task, we need to ensure to
inherit the log context from the current task, otherwise log messages
printed in the handler function are not printed to the task log.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 server/src/parallel_fetcher.rs | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/server/src/parallel_fetcher.rs b/server/src/parallel_fetcher.rs
index 7fb0d162..f07a2de3 100644
--- a/server/src/parallel_fetcher.rs
+++ b/server/src/parallel_fetcher.rs
@@ -8,6 +8,7 @@ use anyhow::Error;
 use tokio::sync::{OwnedSemaphorePermit, Semaphore};
 use tokio::task::JoinSet;
 
+use proxmox_log::LogContext;
 use pve_api_types::ClusterNodeIndexResponse;
 
 use pdm_api_types::remotes::{Remote, RemoteType};
@@ -82,14 +83,19 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
             let semaphore = Arc::clone(&total_connections_semaphore);
 
             let f = func.clone();
-
-            remote_join_set.spawn(Self::fetch_remote(
+            let future = Self::fetch_remote(
                 remote,
                 self.context.clone(),
                 semaphore,
                 f,
                 self.max_connections_per_remote,
-            ));
+            );
+
+            if let Some(log_context) = LogContext::current() {
+                remote_join_set.spawn(log_context.scope(future));
+            } else {
+                remote_join_set.spawn(future);
+            }
         }
 
         let mut results = FetchResults::default();
@@ -160,14 +166,20 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
                     let node_name = node.node.clone();
                     let context_clone = context.clone();
 
-                    nodes_join_set.spawn(Self::fetch_node(
+                    let future = Self::fetch_node(
                         func_clone,
                         context_clone,
                         remote_clone,
                         node_name,
                         permit,
                         Some(per_remote_connections_permit),
-                    ));
+                    );
+
+                    if let Some(log_context) = LogContext::current() {
+                        nodes_join_set.spawn(log_context.scope(future));
+                    } else {
+                        nodes_join_set.spawn(future);
+                    }
                 }
 
                 while let Some(join_result) = nodes_join_set.join_next().await {
@@ -251,15 +263,20 @@ impl<C: Clone + Send + 'static> ParallelFetcher<C> {
             let remote_id = remote.id.clone();
             let context = self.context.clone();
             let func = func.clone();
-
-            node_join_set.spawn(async move {
+            let future = async move {
                 let permit = total_connections_semaphore.acquire_owned().await.unwrap();
 
                 (
                     remote_id,
                     Self::fetch_node(func, context, remote, "localhost".into(), permit, None).await,
                 )
-            });
+            };
+
+            if let Some(log_context) = LogContext::current() {
+                node_join_set.spawn(log_context.scope(future));
+            } else {
+                node_join_set.spawn(future);
+            }
         }
 
         while let Some(a) = node_join_set.join_next().await {
-- 
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 ` Lukas Wagner [this message]
2026-02-04 15:27 ` [PATCH datacenter-manager 3/5] parallel fetcher: add builder and make struct members private Lukas Wagner
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-3-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal