[pbs-devel] [PATCH proxmox-backup 3/6] api2/node/tasks: add optional since/typefilter/statusfilter

Dominik Csapak d.csapak at proxmox.com
Fri Oct 30 15:02:12 CET 2020


and change all users of the /status/tasks api call to this

with this change we can now delete the /status/tasks api call

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/api2/node/tasks.rs       | 47 +++++++++++++++++++++++++++++++++---
 www/Dashboard.js             |  3 ++-
 www/dashboard/TaskSummary.js |  3 ++-
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs
index 00516f3b..8fe2aac1 100644
--- a/src/api2/node/tasks.rs
+++ b/src/api2/node/tasks.rs
@@ -296,6 +296,24 @@ fn stop_task(
                 type: String,
                 description: "Only list tasks from this user.",
             },
+            since: {
+                type: i64,
+                description: "Only list tasks since this UNIX epoch.",
+                optional: true,
+            },
+            typefilter: {
+                optional: true,
+                type: String,
+                description: "Only list tasks whose type contains this.",
+            },
+            statusfilter: {
+                optional: true,
+                type: Array,
+                description: "Only list tasks which have any one of the listed status.",
+                items: {
+                    type: TaskStateType,
+                },
+            },
         },
     },
     returns: {
@@ -315,6 +333,9 @@ pub fn list_tasks(
     errors: bool,
     running: bool,
     userfilter: Option<String>,
+    since: Option<i64>,
+    typefilter: Option<String>,
+    statusfilter: Option<Vec<TaskStateType>>,
     param: Value,
     mut rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<TaskListItem>, Error> {
@@ -331,7 +352,13 @@ pub fn list_tasks(
     let limit = if limit > 0 { limit as usize } else { usize::MAX };
 
     let result: Vec<TaskListItem> = list
-        .take_while(|info| !info.is_err())
+        .take_while(|info| {
+            match (info, since) {
+                (Ok(info), Some(since)) => info.upid.starttime > since,
+                (Ok(_), None) => true,
+                (Err(_), _) => false,
+            }
+        })
         .filter_map(|info| {
         let info = match info {
             Ok(info) => info,
@@ -365,9 +392,21 @@ pub fn list_tasks(
             }
         }
 
-        match info.state {
-            Some(_) if running => return None,
-            Some(crate::server::TaskState::OK { .. }) if errors => return None,
+        if let Some(typefilter) = &typefilter {
+            if !info.upid.worker_type.contains(typefilter) {
+                return None;
+            }
+        }
+
+        match (&info.state, &statusfilter) {
+            (Some(_), _) if running => return None,
+            (Some(crate::server::TaskState::OK { .. }), _) if errors => return None,
+            (Some(state), Some(filters)) => {
+                if !filters.contains(&state.tasktype()) {
+                    return None;
+                }
+            },
+            (None, Some(_)) => return None,
             _ => {},
         }
 
diff --git a/www/Dashboard.js b/www/Dashboard.js
index 122aa559..4f60efff 100644
--- a/www/Dashboard.js
+++ b/www/Dashboard.js
@@ -230,8 +230,9 @@ Ext.define('PBS.Dashboard', {
 		model: 'proxmox-tasks',
 		proxy: {
 		    type: 'proxmox',
-		    url: '/api2/json/status/tasks',
+		    url: '/api2/json/nodes/localhost/tasks',
 		    extraParams: {
+			limit: 0,
 			since: '{sinceEpoch}',
 		    },
 		},
diff --git a/www/dashboard/TaskSummary.js b/www/dashboard/TaskSummary.js
index 6a503979..a9ebec07 100644
--- a/www/dashboard/TaskSummary.js
+++ b/www/dashboard/TaskSummary.js
@@ -39,6 +39,7 @@ Ext.define('PBS.TaskSummary', {
 		let state = me.states[cellindex];
 		let type = me.types[rowindex];
 		let filterParam = {
+		    limit: 0,
 		    'statusfilter': state,
 		    'typefilter': type,
 		};
@@ -111,7 +112,7 @@ Ext.define('PBS.TaskSummary', {
 			    model: 'proxmox-tasks',
 			    proxy: {
 				type: 'proxmox',
-				url: "/api2/json/status/tasks",
+				url: "/api2/json/nodes/localhost/tasks",
 			    },
 			},
 		    });
-- 
2.20.1






More information about the pbs-devel mailing list