[pbs-devel] [PATCH v2 proxmox-backup 2/3] pass worker context to do_create_prune_job

Stefan Lendl s.lendl at proxmox.com
Tue Nov 21 17:21:10 CET 2023


pass the WorkerTaksContext to do_create_prune_job because we want
logging when calling within a worker context.

Signed-off-by: Stefan Lendl <s.lendl at proxmox.com>
---
 src/api2/config/prune.rs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/api2/config/prune.rs b/src/api2/config/prune.rs
index 1e8b5526..4f7ce39c 100644
--- a/src/api2/config/prune.rs
+++ b/src/api2/config/prune.rs
@@ -1,5 +1,7 @@
 use anyhow::Error;
 use hex::FromHex;
+use proxmox_sys::task_log;
+use proxmox_sys::WorkerTaskContext;
 use serde::{Deserialize, Serialize};
 use serde_json::Value;
 
@@ -56,7 +58,10 @@ pub fn list_prune_jobs(
     Ok(list)
 }
 
-pub fn do_create_prune_job(config: PruneJobConfig) -> Result<(), Error> {
+pub fn do_create_prune_job(
+    config: PruneJobConfig,
+    worker: Option<&dyn WorkerTaskContext>,
+) -> Result<(), Error> {
     let _lock = prune::lock_config()?;
 
     let (mut section_config, _digest) = prune::config()?;
@@ -71,6 +76,10 @@ pub fn do_create_prune_job(config: PruneJobConfig) -> Result<(), Error> {
 
     crate::server::jobstate::create_state_file("prunejob", &config.id)?;
 
+    if let Some(worker) = worker {
+        task_log!(worker, "Prune job created: {}", config.id);
+    }
+
     Ok(())
 }
 
@@ -99,7 +108,7 @@ pub fn create_prune_job(
 
     user_info.check_privs(&auth_id, &config.acl_path(), PRIV_DATASTORE_MODIFY, true)?;
 
-    do_create_prune_job(config)
+    do_create_prune_job(config, None)
 }
 
 #[api(
-- 
2.42.0






More information about the pbs-devel mailing list