From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v3 proxmox-backup 06/14] add scheduling for verification jobs
Date: Tue, 13 Oct 2020 11:33:01 +0200 [thread overview]
Message-ID: <20201013093309.14917-7-h.laimer@proxmox.com> (raw)
In-Reply-To: <20201013093309.14917-1-h.laimer@proxmox.com>
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
src/bin/proxmox-backup-proxy.rs | 62 +++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 67fbc541..e8047ecc 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -19,6 +19,7 @@ use proxmox_backup::auth_helpers::*;
use proxmox_backup::tools::disks::{ DiskManage, zfs_pool_stats };
use proxmox_backup::api2::pull::do_sync_job;
+use proxmox_backup::backup::do_verification_job;
fn main() -> Result<(), Error> {
proxmox_backup::tools::setup_safe_path_env();
@@ -198,6 +199,7 @@ async fn schedule_tasks() -> Result<(), Error> {
schedule_datastore_prune().await;
schedule_datastore_verification().await;
schedule_datastore_sync_jobs().await;
+ schedule_datastore_verify_jobs().await;
schedule_task_log_rotate().await;
Ok(())
@@ -656,6 +658,66 @@ async fn schedule_datastore_sync_jobs() {
}
}
+async fn schedule_datastore_verify_jobs() {
+ use proxmox_backup::{
+ config::{ verify::{self, VerificationJobConfig}, jobstate::{self, Job} },
+ tools::systemd::time::{ parse_calendar_event, compute_next_event },
+ };
+ let config = match verify::config() {
+ Err(err) => {
+ eprintln!("unable to read verification job config - {}", err);
+ return;
+ }
+ Ok((config, _digest)) => config,
+ };
+ for (job_id, (_, job_config)) in config.sections {
+ let job_config: VerificationJobConfig = match serde_json::from_value(job_config) {
+ Ok(c) => c,
+ Err(err) => {
+ eprintln!("verification job config from_value failed - {}", err);
+ continue;
+ }
+ };
+ let event_str = match job_config.schedule {
+ Some(ref event_str) => event_str.clone(),
+ None => continue,
+ };
+ let event = match parse_calendar_event(&event_str) {
+ Ok(event) => event,
+ Err(err) => {
+ eprintln!("unable to parse schedule '{}' - {}", event_str, err);
+ continue;
+ }
+ };
+ let worker_type = "verificationjob";
+ let last = match jobstate::last_run_time(worker_type, &job_id) {
+ Ok(time) => time,
+ Err(err) => {
+ eprintln!("could not get last run time of {} {}: {}", worker_type, job_id, err);
+ continue;
+ }
+ };
+ let next = match compute_next_event(&event, last, false) {
+ Ok(Some(next)) => next,
+ Ok(None) => continue,
+ Err(err) => {
+ eprintln!("compute_next_event for '{}' failed - {}", event_str, err);
+ continue;
+ }
+ };
+ let now = proxmox::tools::time::epoch_i64();
+ if next > now { continue; }
+ let job = match Job::new(worker_type, &job_id) {
+ Ok(job) => job,
+ Err(_) => continue, // could not get lock
+ };
+ let userid = Userid::backup_userid().clone();
+ if let Err(err) = do_verification_job(job, job_config, &userid, Some(event_str)) {
+ eprintln!("unable to start datastore verification job {} - {}", &job_id, err);
+ }
+ }
+}
+
async fn schedule_task_log_rotate() {
use proxmox_backup::{
config::jobstate::{self, Job},
--
2.20.1
next prev parent reply other threads:[~2020-10-13 9:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-13 9:32 [pbs-devel] [PATCH v3 proxmox-backup 00/14] add job based verify scheduling Hannes Laimer
2020-10-13 9:32 ` [pbs-devel] [PATCH v3 proxmox-backup 01/14] add two new schemas for verification jobs Hannes Laimer
2020-10-15 16:13 ` Thomas Lamprecht
2020-10-13 9:32 ` [pbs-devel] [PATCH v3 proxmox-backup 02/14] add verification job config Hannes Laimer
2020-10-13 9:32 ` [pbs-devel] [PATCH v3 proxmox-backup 03/14] api2: add verify job config endpoint Hannes Laimer
2020-10-13 9:32 ` [pbs-devel] [PATCH v3 proxmox-backup 04/14] add do_verification_job function to verify.rs Hannes Laimer
2020-10-15 16:15 ` Thomas Lamprecht
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 05/14] api2: add verification job admin endpoint Hannes Laimer
2020-10-13 9:33 ` Hannes Laimer [this message]
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 07/14] set a diffrent worker_type based on what is going to be verified(snapshot, group, ds) Hannes Laimer
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 08/14] ui: add verification job view Hannes Laimer
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 09/14] ui: add verification job edit window Hannes Laimer
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 10/14] ui: add task descriptions for the different types of verification(job, snapshpt, group, ds) Hannes Laimer
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 11/14] remove verify_schedule field from datastore config endpoint Hannes Laimer
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 12/14] remove verify_schedule field from DatastoreConfig Hannes Laimer
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 13/14] remove verify-schedule field from DataStoreEdit and DataStoreConfig Hannes Laimer
2020-10-13 9:33 ` [pbs-devel] [PATCH v3 proxmox-backup 14/14] remove old verification scheduling from proxmox-backup-proxy.rs Hannes Laimer
2020-10-15 16:18 ` Thomas Lamprecht
2020-10-14 11:55 ` [pbs-devel] [PATCH v3 proxmox-backup 00/14] add job based verify scheduling Wolfgang Bumiller
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=20201013093309.14917-7-h.laimer@proxmox.com \
--to=h.laimer@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