public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 4/5] api2/admin/datastore: start the garbage_collection task with our helper
Date: Mon,  2 Nov 2020 12:34:38 +0100	[thread overview]
Message-ID: <20201102113439.26618-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201102113439.26618-1-d.csapak@proxmox.com>

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>
---
 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





  parent reply	other threads:[~2020-11-02 11:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02 11:34 [pbs-devel] [PATCH proxmox-backup 0/5] various bug fixes/improvements for gc Dominik Csapak
2020-11-02 11:34 ` [pbs-devel] [PATCH proxmox-backup 1/5] garbage collect: improve index error messages Dominik Csapak
2020-11-02 11:34 ` [pbs-devel] [PATCH proxmox-backup 2/5] backup/{dynamic, fixed}_index: improve error message for small index files Dominik Csapak
2020-11-02 11:34 ` [pbs-devel] [PATCH proxmox-backup 3/5] server/gc_job: add 'to_stdout' Dominik Csapak
2020-11-02 11:34 ` Dominik Csapak [this message]
2020-11-03  5:45   ` [pbs-devel] [PATCH proxmox-backup 4/5] api2/admin/datastore: start the garbage_collection task with our helper Dietmar Maurer
2020-11-03  6:54     ` Dominik Csapak
2020-11-02 11:34 ` [pbs-devel] [PATCH proxmox-backup 5/5] proxmox-backup-proxy: use only jobstate for garbage_collection schedule Dominik Csapak
2020-11-02 20:12 ` [pbs-devel] applied: [PATCH proxmox-backup 0/5] various bug fixes/improvements for gc Thomas Lamprecht
2020-11-03  5:11   ` Dietmar Maurer
2020-11-03  7:14     ` Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201102113439.26618-5-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal