server/worker_task: factor out task list rendering

we will need this later again

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-09-25 16:13:19 +02:00 committed by Dietmar Maurer
parent 005a5b9677
commit bbeb0256f1

View File

@ -413,15 +413,7 @@ fn update_active_workers(new_upid: Option<&UPID>) -> Result<Vec<TaskListInfo>, E
} }
}); });
let mut raw = String::new(); let raw = render_task_list(&task_list[..]);
for info in &task_list {
if let Some(status) = &info.state {
raw.push_str(&format!("{} {:08X} {}\n", info.upid_str, status.endtime(), status));
} else {
raw.push_str(&info.upid_str);
raw.push('\n');
}
}
replace_file( replace_file(
PROXMOX_BACKUP_ACTIVE_TASK_FN, PROXMOX_BACKUP_ACTIVE_TASK_FN,
@ -443,6 +435,26 @@ pub fn read_task_list() -> Result<Vec<TaskListInfo>, Error> {
update_active_workers(None) update_active_workers(None)
} }
fn render_task_line(info: &TaskListInfo) -> String {
let mut raw = String::new();
if let Some(status) = &info.state {
raw.push_str(&format!("{} {:08X} {}\n", info.upid_str, status.endtime(), status));
} else {
raw.push_str(&info.upid_str);
raw.push('\n');
}
raw
}
fn render_task_list(list: &[TaskListInfo]) -> String {
let mut raw = String::new();
for info in list {
raw.push_str(&render_task_line(&info));
}
raw
}
/// Launch long running worker tasks. /// Launch long running worker tasks.
/// ///
/// A worker task can either be a whole thread, or a simply tokio /// A worker task can either be a whole thread, or a simply tokio