]> git.proxmox.com Git - proxmox-backup.git/blame - src/server/gc_job.rs
use new proxmox-sys crate
[proxmox-backup.git] / src / server / gc_job.rs
CommitLineData
3b707fbb
DM
1use std::sync::Arc;
2use anyhow::Error;
3
d5790a9f
DM
4use proxmox_sys::task_log;
5
6227654a 6use pbs_api_types::Authid;
6d5d305d 7use pbs_datastore::DataStore;
b9700a9f 8use proxmox_rest_server::WorkerTask;
6227654a 9
6d5d305d 10use crate::server::jobstate::Job;
3b707fbb
DM
11
12/// Runs a garbage collection job.
13pub fn do_garbage_collection_job(
14 mut job: Job,
15 datastore: Arc<DataStore>,
16 auth_id: &Authid,
17 schedule: Option<String>,
c724f658 18 to_stdout: bool,
3b707fbb
DM
19) -> Result<String, Error> {
20
3b707fbb
DM
21 let store = datastore.name().to_string();
22
f47c1d3a
DM
23 let (email, notify) = crate::server::lookup_datastore_notify_settings(&store);
24
3b707fbb
DM
25 let worker_type = job.jobtype().to_string();
26 let upid_str = WorkerTask::new_thread(
27 &worker_type,
28 Some(store.clone()),
049a22a3 29 auth_id.to_string(),
c724f658 30 to_stdout,
3b707fbb
DM
31 move |worker| {
32 job.start(&worker.upid().to_string())?;
33
1ec0d70d 34 task_log!(worker, "starting garbage collection on store {}", store);
3b707fbb 35 if let Some(event_str) = schedule {
1ec0d70d 36 task_log!(worker, "task triggered by schedule '{}'", event_str);
3b707fbb
DM
37 }
38
39 let result = datastore.garbage_collection(&*worker, worker.upid());
40
41 let status = worker.create_state(&result);
42
b92cad09
FG
43 if let Err(err) = job.finish(status) {
44 eprintln!(
3b707fbb
DM
45 "could not finish job state for {}: {}",
46 job.jobtype().to_string(),
47 err
b92cad09 48 );
3b707fbb
DM
49 }
50
51 if let Some(email) = email {
52 let gc_status = datastore.last_gc_status();
f47c1d3a 53 if let Err(err) = crate::server::send_gc_status(&email, notify, &store, &gc_status, &result) {
3b707fbb
DM
54 eprintln!("send gc notification failed: {}", err);
55 }
56 }
57
58 result
59 }
60 )?;
61
62 Ok(upid_str)
63}