[pbs-devel] [PATCH proxmox-backup 03/10] server/worker_task: factor out task list rendering

Dominik Csapak d.csapak at proxmox.com
Fri Sep 25 16:13:19 CEST 2020


we will need this later again

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/server/worker_task.rs | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/server/worker_task.rs b/src/server/worker_task.rs
index d220e755..3b47dfb6 100644
--- a/src/server/worker_task.rs
+++ b/src/server/worker_task.rs
@@ -425,15 +425,7 @@ fn update_active_workers(new_upid: Option<&UPID>) -> Result<Vec<TaskListInfo>, E
         }
     });
 
-    let mut raw = String::new();
-    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');
-        }
-    }
+    let raw = render_task_list(&task_list[..]);
 
     replace_file(
         PROXMOX_BACKUP_ACTIVE_TASK_FN,
@@ -455,6 +447,26 @@ pub fn read_task_list() -> Result<Vec<TaskListInfo>, Error> {
     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.
 ///
 /// A worker task can either be a whole thread, or a simply tokio
-- 
2.20.1






More information about the pbs-devel mailing list