api2/status: use the TaskListInfoIterator here

this means that limiting with epoch now works correctly
also change the api type to i64, since that is what the starttime is
saved as

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-09-28 15:32:10 +02:00 committed by Dietmar Maurer
parent 768e10d0b3
commit 6bcfc5c1a4

View File

@ -182,7 +182,7 @@ fn datastore_status(
input: { input: {
properties: { properties: {
since: { since: {
type: u64, type: i64,
description: "Only list tasks since this UNIX epoch.", description: "Only list tasks since this UNIX epoch.",
optional: true, optional: true,
}, },
@ -200,6 +200,7 @@ fn datastore_status(
)] )]
/// List tasks. /// List tasks.
pub fn list_tasks( pub fn list_tasks(
since: Option<i64>,
_param: Value, _param: Value,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Vec<TaskListItem>, Error> { ) -> Result<Vec<TaskListItem>, Error> {
@ -209,13 +210,28 @@ pub fn list_tasks(
let user_privs = user_info.lookup_privs(&userid, &["system", "tasks"]); let user_privs = user_info.lookup_privs(&userid, &["system", "tasks"]);
let list_all = (user_privs & PRIV_SYS_AUDIT) != 0; let list_all = (user_privs & PRIV_SYS_AUDIT) != 0;
let since = since.unwrap_or_else(|| 0);
// TODO: replace with call that gets all task since 'since' epoch let list: Vec<TaskListItem> = server::TaskListInfoIterator::new(false)?
let list: Vec<TaskListItem> = server::read_task_list()? .take_while(|info| {
.into_iter() match info {
.map(TaskListItem::from) Ok(info) => info.upid.starttime > since,
.filter(|entry| list_all || entry.user == userid) Err(_) => false
.collect(); }
})
.filter_map(|info| {
match info {
Ok(info) => {
if list_all || info.upid.userid == userid {
Some(Ok(TaskListItem::from(info)))
} else {
None
}
}
Err(err) => Some(Err(err))
}
})
.collect::<Result<Vec<TaskListItem>, Error>>()?;
Ok(list.into()) Ok(list.into())
} }