implement From<TaskListInfo> for TaskListItem
and use it where its convenient Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
57e50fb906
commit
df528ee6fa
|
@ -323,21 +323,9 @@ pub fn list_tasks(
|
||||||
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
for info in list.iter() {
|
for info in list {
|
||||||
if !list_all && info.upid.username != username { continue; }
|
if !list_all && info.upid.username != username { continue; }
|
||||||
|
|
||||||
let mut entry = TaskListItem {
|
|
||||||
upid: info.upid_str.clone(),
|
|
||||||
node: "localhost".to_string(),
|
|
||||||
pid: info.upid.pid as i64,
|
|
||||||
pstart: info.upid.pstart,
|
|
||||||
starttime: info.upid.starttime,
|
|
||||||
worker_type: info.upid.worker_type.clone(),
|
|
||||||
worker_id: info.upid.worker_id.clone(),
|
|
||||||
user: info.upid.username.clone(),
|
|
||||||
endtime: None,
|
|
||||||
status: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(username) = userfilter {
|
if let Some(username) = userfilter {
|
||||||
if !info.upid.username.contains(username) { continue; }
|
if !info.upid.username.contains(username) { continue; }
|
||||||
|
@ -367,9 +355,6 @@ pub fn list_tasks(
|
||||||
if errors && state.1 == "OK" {
|
if errors && state.1 == "OK" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.endtime = Some(state.0);
|
|
||||||
entry.status = Some(state.1.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count as u64) < start {
|
if (count as u64) < start {
|
||||||
|
@ -379,12 +364,12 @@ pub fn list_tasks(
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.len() as u64) < limit { result.push(entry); };
|
if (result.len() as u64) < limit { result.push(info.into()); };
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcenv["total"] = Value::from(count);
|
rpcenv["total"] = Value::from(count);
|
||||||
|
|
||||||
Ok(result)
|
Ok(result.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sortable]
|
#[sortable]
|
||||||
|
|
|
@ -599,6 +599,27 @@ pub struct TaskListItem {
|
||||||
pub status: Option<String>,
|
pub status: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<crate::server::TaskListInfo> for TaskListItem {
|
||||||
|
fn from(info: crate::server::TaskListInfo) -> Self {
|
||||||
|
let (endtime, status) = info
|
||||||
|
.state
|
||||||
|
.map_or_else(|| (None, None), |(a,b)| (Some(a), Some(b)));
|
||||||
|
|
||||||
|
TaskListItem {
|
||||||
|
upid: info.upid_str,
|
||||||
|
node: "localhost".to_string(),
|
||||||
|
pid: info.upid.pid as i64,
|
||||||
|
pstart: info.upid.pstart,
|
||||||
|
starttime: info.upid.starttime,
|
||||||
|
worker_type: info.upid.worker_type,
|
||||||
|
worker_id: info.upid.worker_id,
|
||||||
|
user: info.upid.username,
|
||||||
|
endtime,
|
||||||
|
status,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[api()]
|
#[api()]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
|
|
Loading…
Reference in New Issue