server/worker_task: let upid_read_status also return the endtime
the endtime should be the timestamp of the last log line or if there is no log at all, the starttime Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
4c116bafb8
commit
ae197dda23
@ -105,7 +105,7 @@ 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(TaskState::Unknown);
|
||||
let (_, exitstatus) = crate::server::upid_read_status(&upid).unwrap_or((0, TaskState::Unknown));
|
||||
result["status"] = Value::from("stopped");
|
||||
result["exitstatus"] = Value::from(exitstatus.to_string());
|
||||
};
|
||||
|
@ -190,9 +190,12 @@ pub fn create_task_log_dirs() -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Read exits status from task log file
|
||||
pub fn upid_read_status(upid: &UPID) -> Result<TaskState, Error> {
|
||||
/// Read endtime (time of last log line) and exitstatus from task log file
|
||||
/// If there is not a single line with at valid datetime, we assume the
|
||||
/// starttime to be the endtime
|
||||
pub fn upid_read_status(upid: &UPID) -> Result<(i64, TaskState), Error> {
|
||||
let mut status = TaskState::Unknown;
|
||||
let mut time = upid.starttime;
|
||||
|
||||
let path = upid.log_path();
|
||||
|
||||
@ -208,9 +211,15 @@ pub fn upid_read_status(upid: &UPID) -> Result<TaskState, Error> {
|
||||
for line in reader.lines() {
|
||||
let line = line?;
|
||||
|
||||
let mut iter = line.splitn(2, ": TASK ");
|
||||
if iter.next() == None { continue; }
|
||||
match iter.next() {
|
||||
let mut iter = line.splitn(2, ": ");
|
||||
if let Some(time_str) = iter.next() {
|
||||
time = chrono::DateTime::parse_from_rfc3339(time_str)
|
||||
.map_err(|err| format_err!("cannot parse '{}': {}", time_str, err))?
|
||||
.timestamp();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
match iter.next().and_then(|rest| rest.strip_prefix("TASK ")) {
|
||||
None => continue,
|
||||
Some(rest) => {
|
||||
if let Ok(state) = rest.parse() {
|
||||
@ -220,7 +229,7 @@ pub fn upid_read_status(upid: &UPID) -> Result<TaskState, Error> {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(status)
|
||||
Ok((time, status))
|
||||
}
|
||||
|
||||
/// Task State
|
||||
@ -325,10 +334,10 @@ fn update_active_workers(new_upid: Option<&UPID>) -> Result<Vec<TaskListInfo>, E
|
||||
},
|
||||
None => {
|
||||
println!("Detected stopped UPID {}", upid_str);
|
||||
let status = upid_read_status(&upid)
|
||||
.unwrap_or_else(|_| TaskState::Unknown);
|
||||
let (time, status) = upid_read_status(&upid)
|
||||
.unwrap_or_else(|_| (Local::now().timestamp(), TaskState::Unknown));
|
||||
finish_list.push(TaskListInfo {
|
||||
upid, upid_str, state: Some((Local::now().timestamp(), status))
|
||||
upid, upid_str, state: Some((time, status))
|
||||
});
|
||||
},
|
||||
Some((endtime, status)) => {
|
||||
|
Loading…
Reference in New Issue
Block a user