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 v2 1/6] pdm-api-types: task-cache: add NativeUpid::node() convenience getter
Date: Mon, 15 Jun 2026 14:58:18 +0200	[thread overview]
Message-ID: <20260615125823.193288-2-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260615125823.193288-1-l.wagner@proxmox.com>

Some callers need to get the 'node' property of a UPID, but handle both,
PBS and PVE equally, making a distinction at the call site inconvenient.
Providing a 'node' getter in NativeUpid simplifies callers a little.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    Changes since v1:
      - Fold in the refactoring that actually uses the 'node()' helper into
        this commit, as suggested by Dominik.

 lib/pdm-api-types/src/remote_upid.rs  | 10 +++++++++
 server/src/remote_tasks/task_cache.rs | 32 ++++++++++-----------------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/lib/pdm-api-types/src/remote_upid.rs b/lib/pdm-api-types/src/remote_upid.rs
index 1e90bef4..194e4a18 100644
--- a/lib/pdm-api-types/src/remote_upid.rs
+++ b/lib/pdm-api-types/src/remote_upid.rs
@@ -26,6 +26,16 @@ pub enum NativeUpid {
     PbsUpid(pbs_api_types::UPID),
 }
 
+impl NativeUpid {
+    /// Convenience getter to query the 'node' property of a task.
+    pub fn node(&self) -> &str {
+        match self {
+            NativeUpid::PveUpid(upid) => upid.node.as_str(),
+            NativeUpid::PbsUpid(upid) => upid.node.as_str(),
+        }
+    }
+}
+
 impl RemoteUpid {
     /// Create a new remote UPID.
     pub fn new(remote: String, remote_type: RemoteType, upid: String) -> Self {
diff --git a/server/src/remote_tasks/task_cache.rs b/server/src/remote_tasks/task_cache.rs
index b8122d6a..412ee770 100644
--- a/server/src/remote_tasks/task_cache.rs
+++ b/server/src/remote_tasks/task_cache.rs
@@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
 
 use proxmox_sys::fs::CreateOptions;
 
-use pdm_api_types::{NativeUpid, RemoteUpid};
+use pdm_api_types::RemoteUpid;
 
 /// Filename for the file containing running tasks.
 const ACTIVE_FILENAME: &str = "active";
@@ -404,27 +404,19 @@ impl WritableTaskCache {
             // Remove this finished task from our set of active tasks.
             active_tasks.remove(&task.upid);
 
-            match task.upid.native_upid() {
-                Ok(NativeUpid::PveUpid(upid)) => {
-                    let node = &upid.node;
-                    let remote = task.upid.remote();
-
-                    if node_success_map.node_successful(remote, node) {
-                        state.update_cutoff_timestamp(remote, node, task.starttime);
-                    }
-                }
-                Ok(NativeUpid::PbsUpid(upid)) => {
-                    let node = &upid.node;
-                    let remote = task.upid.remote();
-
-                    if node_success_map.node_successful(remote, node) {
-                        state.update_cutoff_timestamp(remote, node, task.starttime);
-                    }
-                }
-                Err(error) => {
-                    log::error!("could not parse PVE UPID - not saving to task cache: {error:#}");
+            let native_upid = match task.upid.native_upid() {
+                Ok(native_upid) => native_upid,
+                Err(err) => {
+                    log::error!("could not parse UPID - not saving to task cache: {err:#}");
                     continue;
                 }
+            };
+
+            let node = native_upid.node();
+            let remote = task.upid.remote();
+
+            if node_success_map.node_successful(remote, node) {
+                state.update_cutoff_timestamp(remote, node, task.starttime);
             }
 
             serde_json::to_writer(&mut file, &task)?;
-- 
2.47.3





  reply	other threads:[~2026-06-15 12:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-15 12:58 [PATCH datacenter-manager v2 0/6] fix #7639: task cache: consider running tasks when updating the cutoff timestamp Lukas Wagner
2026-06-15 12:58 ` Lukas Wagner [this message]
2026-06-15 12:58 ` [PATCH datacenter-manager v2 2/6] task cache: tests: allow to provide an explicit end time in 'task' helper Lukas Wagner
2026-06-15 12:58 ` [PATCH datacenter-manager v2 3/6] task cache: tests: add get_cutoff helper Lukas Wagner
2026-06-15 12:58 ` [PATCH datacenter-manager v2 4/6] task cache: tests: add 'make_cache' convenience helper Lukas Wagner
2026-06-15 12:58 ` [PATCH datacenter-manager v2 5/6] fix #7639: task cache: consider running tasks when updating the cutoff timestamp Lukas Wagner
2026-06-15 12:58 ` [PATCH datacenter-manager v2 6/6] task cache: poll known active tasks every 30 seconds 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=20260615125823.193288-2-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