worker_task: refactor log text generator

we will need this elsewhere, so pull it out

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-07-31 14:43:23 +02:00 committed by Dietmar Maurer
parent eeb19aeb2d
commit cef03f4149
1 changed files with 11 additions and 5 deletions

View File

@ -502,17 +502,23 @@ impl WorkerTask {
Ok(upid_str) Ok(upid_str)
} }
/// Log task result, remove task from running list /// get the Text of the result
pub fn log_result(&self, result: &Result<(), Error>) { pub fn get_log_text(&self, result: &Result<(), Error>) -> String {
let warn_count = self.data.lock().unwrap().warn_count; let warn_count = self.data.lock().unwrap().warn_count;
if let Err(err) = result { if let Err(err) = result {
self.log(&format!("TASK ERROR: {}", err)); format!("ERROR: {}", err)
} else if warn_count > 0 { } else if warn_count > 0 {
self.log(format!("TASK WARNINGS: {}", warn_count)); format!("WARNINGS: {}", warn_count)
} else { } else {
self.log("TASK OK"); "OK".to_string()
} }
}
/// Log task result, remove task from running list
pub fn log_result(&self, result: &Result<(), Error>) {
self.log(format!("TASK {}", self.get_log_text(result)));
WORKER_TASK_LIST.lock().unwrap().remove(&self.upid.task_id); WORKER_TASK_LIST.lock().unwrap().remove(&self.upid.task_id);
let _ = update_active_workers(None); let _ = update_active_workers(None);