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: SPAM: [PATCH datacenter-manager] api: local/remote tasks: simplify errors/statusfilter logic
Date: Mon, 31 Aug 2026 13:45:54 +0200	[thread overview]
Message-ID: <20260831114554.831287-1-l.wagner@proxmox.com> (raw)

`errors` is semantically a subset of `statusfilter`, so we can simplify
the code quite a bit if we include the behavior controlled by `errors`
into `statusfilter` and then only filter based on the latter.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 server/src/api/nodes/tasks.rs  | 31 +++++++++++++++++++++++--------
 server/src/remote_tasks/mod.rs | 26 +++++++++++++++++---------
 2 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/server/src/api/nodes/tasks.rs b/server/src/api/nodes/tasks.rs
index 1cca3c0a..7f96656a 100644
--- a/server/src/api/nodes/tasks.rs
+++ b/server/src/api/nodes/tasks.rs
@@ -88,6 +88,16 @@ pub fn list_tasks(
         statusfilter,
     } = filters;
 
+    let mut statusfilter = statusfilter.unwrap_or_default();
+    if errors {
+        // Contrary to popular belief, `errors` returns more than just errors...
+        statusfilter.extend([
+            TaskStateType::Error,
+            TaskStateType::Unknown,
+            TaskStateType::Warning,
+        ]);
+    }
+
     let auth_id: Authid = rpcenv
         .get_auth_id()
         .context("no authid available")?
@@ -147,17 +157,22 @@ pub fn list_tasks(
             }
         }
 
-        match (&info.state, &statusfilter) {
-            (Some(_), _) if running => continue,
-            (Some(TaskState::OK { .. }), _) if errors => continue,
-            (Some(state), Some(filters)) => {
-                if !filters.contains(&tasktype(state)) {
+        if info.state.is_some() && running {
+            // if there is a task state and we filter by `running`, don't return the task
+            continue;
+        }
+
+        if !statusfilter.is_empty() {
+            if let Some(state) = &info.state {
+                if !statusfilter.contains(&tasktype(state)) {
+                    // A finished task is filtered out if its state is not contained in
+                    // the list of allowed values
                     continue;
                 }
+            } else {
+                // an unfinished task is filtered out if *any* status filter is set
+                continue;
             }
-            (None, _) if errors => continue,
-            (None, Some(_)) => continue,
-            _ => {}
         }
 
         if skipped < start as usize {
diff --git a/server/src/remote_tasks/mod.rs b/server/src/remote_tasks/mod.rs
index bcae7f4c..05a875d6 100644
--- a/server/src/remote_tasks/mod.rs
+++ b/server/src/remote_tasks/mod.rs
@@ -51,6 +51,16 @@ pub async fn get_tasks(
             limit => limit as usize,
         };
 
+        let mut status_filter = filters.statusfilter.unwrap_or_default();
+        if filters.errors {
+            // Contrary to popular belief, `errors` returns more than just errors...
+            status_filter.extend([
+                TaskStateType::Error,
+                TaskStateType::Unknown,
+                TaskStateType::Warning,
+            ]);
+        }
+
         let returned_tasks = cache
             .get_tasks(which)?
             .filter_map(|task| {
@@ -140,16 +150,14 @@ pub async fn get_tasks(
 
                 let state = item.status.as_deref().map(TaskStateType::new_from_str);
 
-                match (state, &filters.statusfilter) {
-                    (Some(TaskStateType::OK), _) if filters.errors => return false,
-                    (Some(state), Some(filters)) => {
-                        if !filters.contains(&state) {
-                            return false;
-                        }
+                if !status_filter.is_empty() {
+                    if let Some(state) = &state {
+                        // Only apply status filters against finished tasks.
+                        return status_filter.contains(state);
+                    } else {
+                        // If status filters are set, a running task should not be returned.
+                        return false;
                     }
-                    (None, Some(_)) => return false,
-                    (None, _) if filters.errors => return false,
-                    _ => {}
                 }
 
                 true
-- 
2.47.3





             reply	other threads:[~2026-08-31 11:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 11:45 Lukas Wagner [this message]
2026-08-31 12:21 ` SPAM: [PATCH datacenter-manager] api: local/remote tasks: simplify errors/statusfilter logic Jonas Theisen
2026-09-03 12:15 ` obsolete: " 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=20260831114554.831287-1-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