src/server/formatter.rs: impl. new result attribute "active"
This commit is contained in:
parent
102d8d4136
commit
6b508dd563
|
@ -63,8 +63,12 @@ fn read_task_log(
|
|||
) -> Result<Value, Error> {
|
||||
|
||||
let upid = extract_upid(¶m)?;
|
||||
|
||||
let test_status = param["test-status"].as_bool().unwrap_or(false);
|
||||
|
||||
let start = param["start"].as_u64().unwrap_or(0);
|
||||
let mut limit = param["limit"].as_u64().unwrap_or(50);
|
||||
|
||||
let mut count: u64 = 0;
|
||||
|
||||
let path = upid.log_path();
|
||||
|
@ -93,6 +97,11 @@ fn read_task_log(
|
|||
|
||||
rpcenv.set_result_attrib("total", Value::from(count));
|
||||
|
||||
if test_status {
|
||||
let active = crate::server::worker_is_active(&upid);
|
||||
rpcenv.set_result_attrib("active", Value::from(active));
|
||||
}
|
||||
|
||||
Ok(json!(lines))
|
||||
}
|
||||
|
||||
|
@ -184,6 +193,12 @@ const UPID_API_SUBDIRS: SubdirMap = &[
|
|||
"Read task log.",
|
||||
&sorted!([
|
||||
("node", false, &NODE_SCHEMA),
|
||||
( "test-status",
|
||||
true,
|
||||
&BooleanSchema::new(
|
||||
"Test task status, and set result attribute \"active\" accordingly."
|
||||
).schema()
|
||||
),
|
||||
("upid", false, &UPID_SCHEMA),
|
||||
("start", true, &IntegerSchema::new("Start at this line.")
|
||||
.minimum(0)
|
||||
|
|
|
@ -39,19 +39,28 @@ pub fn json_data_response(data: Value) -> Response<Body> {
|
|||
response
|
||||
}
|
||||
|
||||
fn add_result_attributes(result: &mut Value, rpcenv: &dyn RpcEnvironment)
|
||||
{
|
||||
if let Some(total) = rpcenv.get_result_attrib("total").and_then(|v| v.as_u64()) {
|
||||
result["total"] = Value::from(total);
|
||||
}
|
||||
|
||||
if let Some(active) = rpcenv.get_result_attrib("active").and_then(|v| v.as_bool()) {
|
||||
result["active"] = Value::from(active);
|
||||
}
|
||||
|
||||
if let Some(changes) = rpcenv.get_result_attrib("changes") {
|
||||
result["changes"] = changes.clone();
|
||||
}
|
||||
}
|
||||
|
||||
fn json_format_data(data: Value, rpcenv: &dyn RpcEnvironment) -> Response<Body> {
|
||||
|
||||
let mut result = json!({
|
||||
"data": data
|
||||
});
|
||||
|
||||
if let Some(total) = rpcenv.get_result_attrib("total").and_then(|v| v.as_u64()) {
|
||||
result["total"] = Value::from(total);
|
||||
}
|
||||
|
||||
if let Some(changes) = rpcenv.get_result_attrib("changes") {
|
||||
result["changes"] = changes.clone();
|
||||
}
|
||||
add_result_attributes(&mut result, rpcenv);
|
||||
|
||||
json_data_response(result)
|
||||
}
|
||||
|
@ -89,14 +98,7 @@ fn extjs_format_data(data: Value, rpcenv: &dyn RpcEnvironment) -> Response<Body>
|
|||
"success": true
|
||||
});
|
||||
|
||||
if let Some(total) = rpcenv.get_result_attrib("total").and_then(|v| v.as_u64()) {
|
||||
result["total"] = Value::from(total);
|
||||
}
|
||||
|
||||
if let Some(changes) = rpcenv.get_result_attrib("changes") {
|
||||
result["changes"] = changes.clone();
|
||||
}
|
||||
|
||||
add_result_attributes(&mut result, rpcenv);
|
||||
|
||||
json_data_response(result)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue