src/api2/types.rs: define and use struct TaskListItem
This commit is contained in:
parent
2c4b303c62
commit
99384f7933
@ -156,14 +156,7 @@ fn stop_task(
|
|||||||
returns: {
|
returns: {
|
||||||
description: "A list of tasks.",
|
description: "A list of tasks.",
|
||||||
type: Array,
|
type: Array,
|
||||||
items: {
|
items: { type: TaskListItem },
|
||||||
description: "Task properties.",
|
|
||||||
type: Object,
|
|
||||||
properties: {
|
|
||||||
upid: { schema: UPID_SCHEMA },
|
|
||||||
// fixme: add other properties
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// List tasks.
|
/// List tasks.
|
||||||
@ -171,7 +164,7 @@ fn list_tasks(
|
|||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
rpcenv: &mut dyn RpcEnvironment,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Vec<TaskListItem>, Error> {
|
||||||
|
|
||||||
let start = param["start"].as_u64().unwrap_or(0);
|
let start = param["start"].as_u64().unwrap_or(0);
|
||||||
let limit = param["limit"].as_u64().unwrap_or(50);
|
let limit = param["limit"].as_u64().unwrap_or(50);
|
||||||
@ -189,16 +182,18 @@ fn list_tasks(
|
|||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
for info in list.iter() {
|
for info in list.iter() {
|
||||||
let mut entry = json!({
|
let mut entry = TaskListItem {
|
||||||
"upid": info.upid_str,
|
upid: info.upid_str.clone(),
|
||||||
"node": "localhost",
|
node: "localhost".to_string(),
|
||||||
"pid": info.upid.pid,
|
pid: info.upid.pid as i64,
|
||||||
"pstart": info.upid.pstart,
|
pstart: info.upid.pstart,
|
||||||
"starttime": info.upid.starttime,
|
starttime: info.upid.starttime,
|
||||||
"type": info.upid.worker_type,
|
worker_type: info.upid.worker_type.clone(),
|
||||||
"id": info.upid.worker_id,
|
worker_id: info.upid.worker_id.clone(),
|
||||||
"user": info.upid.username,
|
user: info.upid.username.clone(),
|
||||||
});
|
endtime: None,
|
||||||
|
status: None,
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(username) = userfilter {
|
if let Some(username) = userfilter {
|
||||||
if !info.upid.username.contains(username) { continue; }
|
if !info.upid.username.contains(username) { continue; }
|
||||||
@ -229,8 +224,8 @@ fn list_tasks(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry["endtime"] = Value::from(state.0);
|
entry.endtime = Some(state.0);
|
||||||
entry["status"] = Value::from(state.1.clone());
|
entry.status = Some(state.1.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count as u64) < start {
|
if (count as u64) < start {
|
||||||
@ -245,7 +240,7 @@ fn list_tasks(
|
|||||||
|
|
||||||
rpcenv.set_result_attrib("total", Value::from(count));
|
rpcenv.set_result_attrib("total", Value::from(count));
|
||||||
|
|
||||||
Ok(json!(result))
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sortable]
|
#[sortable]
|
||||||
|
@ -342,6 +342,37 @@ pub struct StorageStatus {
|
|||||||
pub avail: u64,
|
pub avail: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[api(
|
||||||
|
properties: {
|
||||||
|
"upid": { schema: UPID_SCHEMA },
|
||||||
|
},
|
||||||
|
)]
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
/// Task properties.
|
||||||
|
pub struct TaskListItem {
|
||||||
|
pub upid: String,
|
||||||
|
/// The node name where the task is running on.
|
||||||
|
pub node: String,
|
||||||
|
/// The Unix PID
|
||||||
|
pub pid: i64,
|
||||||
|
/// The task start time (Epoch)
|
||||||
|
pub pstart: u64,
|
||||||
|
/// The task start time (Epoch)
|
||||||
|
pub starttime: i64,
|
||||||
|
/// Worker type (arbitrary ASCII string)
|
||||||
|
pub worker_type: String,
|
||||||
|
/// Worker ID (arbitrary ASCII string)
|
||||||
|
pub worker_id: Option<String>,
|
||||||
|
/// The user who started the task
|
||||||
|
pub user: String,
|
||||||
|
/// The task end time (Epoch)
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub endtime: Option<i64>,
|
||||||
|
/// Task end status
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub status: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
// Regression tests
|
// Regression tests
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user