public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 2/6] api2/status: add type- and statusfilter to tasks api call
Date: Tue,  6 Oct 2020 12:25:24 +0200	[thread overview]
Message-ID: <20201006102528.15383-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201006102528.15383-1-d.csapak@proxmox.com>

we will use this for the pbs dashboard

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/api2/status.rs | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/api2/status.rs b/src/api2/status.rs
index fd40f14d..372b4822 100644
--- a/src/api2/status.rs
+++ b/src/api2/status.rs
@@ -17,6 +17,7 @@ use crate::api2::types::{
     RRDMode,
     RRDTimeFrameResolution,
     TaskListItem,
+    TaskStateType,
     Userid,
 };
 
@@ -186,6 +187,19 @@ fn datastore_status(
                 description: "Only list tasks since this UNIX epoch.",
                 optional: true,
             },
+            typefilter: {
+                optional: true,
+                type: String,
+                description: "Only list tasks, whose type contains this string.",
+            },
+            statusfilter: {
+                optional: true,
+                type: Array,
+                description: "Only list tasks which have any one of the listed status.",
+                items: {
+                    type: TaskStateType,
+                },
+            },
         },
     },
     returns: {
@@ -201,6 +215,8 @@ fn datastore_status(
 /// List tasks.
 pub fn list_tasks(
     since: Option<i64>,
+    typefilter: Option<String>,
+    statusfilter: Option<Vec<TaskStateType>>,
     _param: Value,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<TaskListItem>, Error> {
@@ -223,6 +239,27 @@ pub fn list_tasks(
             match info {
                 Ok(info) => {
                     if list_all || info.upid.userid == userid {
+                        if let Some(filter) = &typefilter {
+                            if !info.upid.worker_type.contains(filter) {
+                                return None;
+                            }
+                        }
+
+                        if let Some(filters) = &statusfilter {
+                            if let Some(state) = &info.state {
+                                let statetype = match state {
+                                    server::TaskState::OK { .. } => TaskStateType::OK,
+                                    server::TaskState::Unknown { .. } => TaskStateType::Unknown,
+                                    server::TaskState::Error { .. } => TaskStateType::Error,
+                                    server::TaskState::Warning { .. } => TaskStateType::Warning,
+                                };
+
+                                if !filters.contains(&statetype) {
+                                    return None;
+                                }
+                            }
+                        }
+
                         Some(Ok(TaskListItem::from(info)))
                     } else {
                         None
-- 
2.20.1





  reply	other threads:[~2020-10-06 10:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06 10:25 [pbs-devel] [PATCH proxmox-backup v2 1/6] api2/types: add TaskStateType struct Dominik Csapak
2020-10-06 10:25 ` Dominik Csapak [this message]
2020-10-06 10:25 ` [pbs-devel] [PATCH proxmox-backup v2 3/6] ui: implment task history limit and make it configurable Dominik Csapak
2020-10-06 10:53   ` Thomas Lamprecht
2020-10-06 11:25     ` Dominik Csapak
2020-10-06 10:25 ` [pbs-devel] [PATCH proxmox-backup v2 4/6] ui: Dashboard/TaskSummary: refactor types and title Dominik Csapak
2020-10-06 10:25 ` [pbs-devel] [PATCH proxmox-backup v2 5/6] ui: Dashboard/TaskSummary: add Verifies to the Summary Dominik Csapak
2020-10-06 11:10   ` Thomas Lamprecht
2020-10-06 11:25     ` Thomas Lamprecht
2020-10-06 10:25 ` [pbs-devel] [PATCH proxmox-backup v2 6/6] ui: Dashboard/TaskSummary: show task overlay when clicking on a count Dominik Csapak
2020-10-06 14:07 ` [pbs-devel] applied-series: [PATCH proxmox-backup v2 1/6] api2/types: add TaskStateType struct Thomas Lamprecht

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=20201006102528.15383-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-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