From 567d3e00fb23b112b496955090ea2425d1e33c25 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 11 Dec 2019 12:53:34 +0100 Subject: [PATCH] src/api2/node/tasks.rs: new filter "store" to filter tasks for one store --- src/api2/node/tasks.rs | 20 ++++++++++++++++++++ src/bin/proxmox-backup-client.rs | 8 +++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs index bb8b6b7b..c26c7af2 100644 --- a/src/api2/node/tasks.rs +++ b/src/api2/node/tasks.rs @@ -126,6 +126,8 @@ fn list_tasks( let errors = param["errors"].as_bool().unwrap_or(false); let running = param["running"].as_bool().unwrap_or(false); + let store = param["store"].as_str(); + let userfilter = param["userfilter"].as_str(); let list = server::read_task_list()?; @@ -150,6 +152,23 @@ fn list_tasks( if !info.upid.username.contains(username) { continue; } } + if let Some(store) = store { + // Note: useful to select all tasks spawned by proxmox-backup-client + let worker_id = match &info.upid.worker_id { + Some(w) => w, + None => continue, // skip + }; + + if info.upid.worker_type == "backup" || info.upid.worker_type == "restore" { + let prefix = format!("{}_", store); + if !worker_id.starts_with(&prefix) { continue; } + } else if info.upid.worker_type == "prune" || info.upid.worker_type == "garbage_collection" { + if worker_id != store { continue; } + } else { + continue; // skip + } + } + if let Some(ref state) = info.state { if running { continue; } if errors && state.1 == "OK" { @@ -261,6 +280,7 @@ pub const ROUTER: Router = Router::new() .default(50) .schema() ), + ("store", true, &StringSchema::new("Only lists tasks for datastore name.").schema()), ("running", true, &BooleanSchema::new("Only list running tasks.").schema()), ("errors", true, &BooleanSchema::new("Only list erroneous tasks.").schema()), ("userfilter", true, &StringSchema::new("Only list tasks from this user.").schema()), diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 6f4b6880..56159144 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -1980,7 +1980,13 @@ fn task_list(param: Value) -> Result { let limit = param["limit"].as_u64().unwrap_or(50) as usize; - let args = json!({ "running": true, "start": 0, "limit": limit, "userfilter": repo.user()}); + let args = json!({ + "running": true, + "start": 0, + "limit": limit, + "userfilter": repo.user(), + "store": repo.store(), + }); let result = client.get("api2/json/nodes/localhost/tasks", Some(args)).await?; let data = &result["data"];