server: change status of a task from a string to an enum
representing a state via an enum makes more sense in this case we also implement FromStr and Display to make it easy to convet from/to a string Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
df30017ff8
commit
4c116bafb8
@ -56,7 +56,7 @@ pub fn list_sync_jobs(
|
||||
if let Some(task) = last_tasks.get(&job.id) {
|
||||
job.last_run_upid = Some(task.upid_str.clone());
|
||||
if let Some((endtime, status)) = &task.state {
|
||||
job.last_run_state = Some(String::from(status));
|
||||
job.last_run_state = Some(status.to_string());
|
||||
job.last_run_endtime = Some(*endtime);
|
||||
last = *endtime;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use proxmox::{identity, list_subdirs_api_method, sortable};
|
||||
|
||||
use crate::tools;
|
||||
use crate::api2::types::*;
|
||||
use crate::server::{self, UPID};
|
||||
use crate::server::{self, UPID, TaskState};
|
||||
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
|
||||
use crate::config::cached_user_info::CachedUserInfo;
|
||||
|
||||
@ -105,9 +105,9 @@ async fn get_task_status(
|
||||
if crate::server::worker_is_active(&upid).await? {
|
||||
result["status"] = Value::from("running");
|
||||
} else {
|
||||
let exitstatus = crate::server::upid_read_status(&upid).unwrap_or(String::from("unknown"));
|
||||
let exitstatus = crate::server::upid_read_status(&upid).unwrap_or(TaskState::Unknown);
|
||||
result["status"] = Value::from("stopped");
|
||||
result["exitstatus"] = Value::from(exitstatus);
|
||||
result["exitstatus"] = Value::from(exitstatus.to_string());
|
||||
};
|
||||
|
||||
Ok(result)
|
||||
@ -352,7 +352,7 @@ pub fn list_tasks(
|
||||
|
||||
if let Some(ref state) = info.state {
|
||||
if running { continue; }
|
||||
if errors && state.1 == "OK" {
|
||||
if errors && state.1 == crate::server::TaskState::OK {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -595,7 +595,7 @@ 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)));
|
||||
.map_or_else(|| (None, None), |(a,b)| (Some(a), Some(b.to_string())));
|
||||
|
||||
TaskListItem {
|
||||
upid: info.upid_str,
|
||||
|
Reference in New Issue
Block a user