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 <d.csapak@proxmox.com>
This commit is contained in:
parent
e7dd169fdf
commit
a2a7dd1535
|
@ -296,6 +296,24 @@ fn stop_task(
|
||||||
type: String,
|
type: String,
|
||||||
description: "Only list tasks from this user.",
|
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: {
|
returns: {
|
||||||
|
@ -315,6 +333,9 @@ pub fn list_tasks(
|
||||||
errors: bool,
|
errors: bool,
|
||||||
running: bool,
|
running: bool,
|
||||||
userfilter: Option<String>,
|
userfilter: Option<String>,
|
||||||
|
since: Option<i64>,
|
||||||
|
typefilter: Option<String>,
|
||||||
|
statusfilter: Option<Vec<TaskStateType>>,
|
||||||
param: Value,
|
param: Value,
|
||||||
mut rpcenv: &mut dyn RpcEnvironment,
|
mut rpcenv: &mut dyn RpcEnvironment,
|
||||||
) -> Result<Vec<TaskListItem>, Error> {
|
) -> Result<Vec<TaskListItem>, Error> {
|
||||||
|
@ -331,7 +352,13 @@ pub fn list_tasks(
|
||||||
let limit = if limit > 0 { limit as usize } else { usize::MAX };
|
let limit = if limit > 0 { limit as usize } else { usize::MAX };
|
||||||
|
|
||||||
let result: Vec<TaskListItem> = list
|
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| {
|
.filter_map(|info| {
|
||||||
let info = match info {
|
let info = match info {
|
||||||
Ok(info) => info,
|
Ok(info) => info,
|
||||||
|
@ -365,9 +392,21 @@ pub fn list_tasks(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match info.state {
|
if let Some(typefilter) = &typefilter {
|
||||||
Some(_) if running => return None,
|
if !info.upid.worker_type.contains(typefilter) {
|
||||||
Some(crate::server::TaskState::OK { .. }) if errors => return None,
|
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,
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,8 +232,9 @@ Ext.define('PBS.Dashboard', {
|
||||||
model: 'proxmox-tasks',
|
model: 'proxmox-tasks',
|
||||||
proxy: {
|
proxy: {
|
||||||
type: 'proxmox',
|
type: 'proxmox',
|
||||||
url: '/api2/json/status/tasks',
|
url: '/api2/json/nodes/localhost/tasks',
|
||||||
extraParams: {
|
extraParams: {
|
||||||
|
limit: 0,
|
||||||
since: '{sinceEpoch}',
|
since: '{sinceEpoch}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -39,6 +39,7 @@ Ext.define('PBS.TaskSummary', {
|
||||||
let state = me.states[cellindex];
|
let state = me.states[cellindex];
|
||||||
let type = me.types[rowindex];
|
let type = me.types[rowindex];
|
||||||
let filterParam = {
|
let filterParam = {
|
||||||
|
limit: 0,
|
||||||
'statusfilter': state,
|
'statusfilter': state,
|
||||||
'typefilter': type,
|
'typefilter': type,
|
||||||
};
|
};
|
||||||
|
@ -111,7 +112,7 @@ Ext.define('PBS.TaskSummary', {
|
||||||
model: 'proxmox-tasks',
|
model: 'proxmox-tasks',
|
||||||
proxy: {
|
proxy: {
|
||||||
type: 'proxmox',
|
type: 'proxmox',
|
||||||
url: "/api2/json/status/tasks",
|
url: "/api2/json/nodes/localhost/tasks",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue