From a2a7dd1535f018b129c62f60695f8ea3259a41c4 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 30 Oct 2020 15:02:12 +0100 Subject: [PATCH] api2/node/tasks: add optional since/typefilter/statusfilter 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 --- 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, + since: Option, + typefilter: Option, + statusfilter: Option>, param: Value, mut rpcenv: &mut dyn RpcEnvironment, ) -> Result, Error> { @@ -331,7 +352,13 @@ pub fn list_tasks( let limit = if limit > 0 { limit as usize } else { usize::MAX }; let result: Vec = 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 553c2b58..6d5ccc27 100644 --- a/www/Dashboard.js +++ b/www/Dashboard.js @@ -232,8 +232,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", }, }, });