src/api2/node/tasks.rs: implement stop_task api

This commit is contained in:
Dietmar Maurer 2019-04-10 13:55:05 +02:00
parent 98a181f055
commit a665dea128
1 changed files with 22 additions and 0 deletions

View File

@ -92,6 +92,21 @@ fn read_task_log(
Ok(json!(lines))
}
fn stop_task(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let upid = extract_upid(&param)?;
if crate::server::worker_is_active(&upid) {
server::abort_worker_async(upid);
}
Ok(Value::Null)
}
fn list_tasks(
param: Value,
_info: &ApiMethod,
@ -171,6 +186,13 @@ pub fn router() -> Router {
.required("node", crate::api2::node::NODE_SCHEMA.clone())
.required("upid", upid_schema.clone()))
)
.delete(ApiMethod::new(
stop_task,
ObjectSchema::new("Try to stop a task.")
.required("node", crate::api2::node::NODE_SCHEMA.clone())
.required("upid", upid_schema.clone())).protected(true)
)
.subdir(
"log", Router::new()
.get(