From a665dea1280a3d9b9faa1a3aa1085b97ec018426 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 10 Apr 2019 13:55:05 +0200 Subject: [PATCH] src/api2/node/tasks.rs: implement stop_task api --- src/api2/node/tasks.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs index 039383bd..a0b7c652 100644 --- a/src/api2/node/tasks.rs +++ b/src/api2/node/tasks.rs @@ -92,6 +92,21 @@ fn read_task_log( Ok(json!(lines)) } +fn stop_task( + param: Value, + _info: &ApiMethod, + _rpcenv: &mut RpcEnvironment, +) -> Result { + + let upid = extract_upid(¶m)?; + + 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(