api2/admin/datastore: start the garbage_collection task with our helper

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@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-11-02 12:34:38 +01:00 committed by Thomas Lamprecht
parent c724f65805
commit 4fdf5ddf5b
1 changed files with 5 additions and 12 deletions

View File

@ -29,7 +29,7 @@ use crate::backup::*;
use crate::config::datastore; use crate::config::datastore;
use crate::config::cached_user_info::CachedUserInfo; use crate::config::cached_user_info::CachedUserInfo;
use crate::server::WorkerTask; use crate::server::{jobstate::Job, WorkerTask};
use crate::tools::{ use crate::tools::{
self, self,
zip::{ZipEncoder, ZipEntry}, zip::{ZipEncoder, ZipEntry},
@ -856,20 +856,13 @@ fn start_garbage_collection(
let datastore = DataStore::lookup_datastore(&store)?; let datastore = DataStore::lookup_datastore(&store)?;
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; 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 to_stdout = if rpcenv.env_type() == RpcEnvironmentType::CLI { true } else { false };
let upid_str = WorkerTask::new_thread( let upid_str = crate::server::do_garbage_collection_job(job, datastore, &auth_id, None, to_stdout)
"garbage_collection", .map_err(|err| format_err!("unable to start garbage collection job on datastore {} - {}", store, err))?;
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())
},
)?;
Ok(json!(upid_str)) Ok(json!(upid_str))
} }