src/api2/node/tasks.rs: add "running" filter to list only running tasks

This commit is contained in:
Dietmar Maurer 2019-12-11 10:52:27 +01:00
parent 8560fe3e5f
commit 6d04612955
2 changed files with 4 additions and 1 deletions

View File

@ -124,6 +124,7 @@ fn list_tasks(
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);
let errors = param["errors"].as_bool().unwrap_or(false); let errors = param["errors"].as_bool().unwrap_or(false);
let running = param["running"].as_bool().unwrap_or(false);
let userfilter = param["userfilter"].as_str(); let userfilter = param["userfilter"].as_str();
@ -150,6 +151,7 @@ fn list_tasks(
} }
if let Some(ref state) = info.state { if let Some(ref state) = info.state {
if running { continue; }
if errors && state.1 == "OK" { if errors && state.1 == "OK" {
continue; continue;
} }
@ -259,6 +261,7 @@ pub const ROUTER: Router = Router::new()
.default(50) .default(50)
.schema() .schema()
), ),
("running", true, &BooleanSchema::new("Only list running tasks.").schema()),
("errors", true, &BooleanSchema::new("Only list erroneous tasks.").schema()), ("errors", true, &BooleanSchema::new("Only list erroneous tasks.").schema()),
("userfilter", true, &StringSchema::new("Only list tasks from this user.").schema()), ("userfilter", true, &StringSchema::new("Only list tasks from this user.").schema()),
]), ]),

View File

@ -1980,7 +1980,7 @@ fn task_list(param: Value) -> Result<Value, Error> {
let limit = param["limit"].as_u64().unwrap_or(50) as usize; let limit = param["limit"].as_u64().unwrap_or(50) as usize;
let args = json!({ "start": 0, "limit": limit, "userfilter": repo.user()}); let args = json!({ "running": true, "start": 0, "limit": limit, "userfilter": repo.user()});
let result = client.get("api2/json/nodes/localhost/tasks", Some(args)).await?; let result = client.get("api2/json/nodes/localhost/tasks", Some(args)).await?;
let data = &result["data"]; let data = &result["data"];