[pbs-devel] [PATCH proxmox-backup 4/5] api2/admin/datastore: start the garbage_collection task with our helper
Dominik Csapak
d.csapak at proxmox.com
Mon Nov 2 12:34:38 CET 2020
instead of manually, this has the advantage that we now set
the jobstate correctly and can return with an error if it is
currently running (instead of failing in the task)
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/api2/admin/datastore.rs | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 220f06ae..a5d3e979 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -29,7 +29,7 @@ use crate::backup::*;
use crate::config::datastore;
use crate::config::cached_user_info::CachedUserInfo;
-use crate::server::WorkerTask;
+use crate::server::{jobstate::Job, WorkerTask};
use crate::tools::{
self,
zip::{ZipEncoder, ZipEntry},
@@ -856,20 +856,13 @@ fn start_garbage_collection(
let datastore = DataStore::lookup_datastore(&store)?;
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
- println!("Starting garbage collection on store {}", store);
+ let job = Job::new("garbage_collection", &store)
+ .map_err(|_| format_err!("garbage collection already running"))?;
let to_stdout = if rpcenv.env_type() == RpcEnvironmentType::CLI { true } else { false };
- let upid_str = WorkerTask::new_thread(
- "garbage_collection",
- Some(store.clone()),
- auth_id.clone(),
- to_stdout,
- move |worker| {
- worker.log(format!("starting garbage collection on store {}", store));
- datastore.garbage_collection(&*worker, worker.upid())
- },
- )?;
+ let upid_str = crate::server::do_garbage_collection_job(job, datastore, &auth_id, None, to_stdout)
+ .map_err(|err| format_err!("unable to start garbage collection job on datastore {} - {}", store, err))?;
Ok(json!(upid_str))
}
--
2.20.1
More information about the pbs-devel
mailing list