From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 44CBB63F42 for ; Thu, 29 Oct 2020 11:38:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 42ABF278BE for ; Thu, 29 Oct 2020 11:38:10 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 5E1AB278A5 for ; Thu, 29 Oct 2020 11:38:08 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2645B45F8A for ; Thu, 29 Oct 2020 11:38:08 +0100 (CET) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Thu, 29 Oct 2020 11:37:49 +0100 Message-Id: <20201029103749.109210-3-h.laimer@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201029103749.109210-1-h.laimer@proxmox.com> References: <20201029103749.109210-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox-backup-proxy.rs] Subject: [pbs-devel] [PATCH proxmox-backup 2/2] proxy: extract commonly used logic for scheduling into new function X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Oct 2020 10:38:10 -0000 Signed-off-by: Hannes Laimer --- src/bin/proxmox-backup-proxy.rs | 188 ++++++++++---------------------- 1 file changed, 56 insertions(+), 132 deletions(-) diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 21c5e9fb..9222b075 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -402,48 +402,19 @@ async fn schedule_datastore_prune() { 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 = "prune"; + if check_schedule(worker_type.to_string(), event_str.clone(), store.clone()) { + let job = match Job::new(worker_type, &store) { + Ok(job) => job, + Err(_) => continue, // could not get lock + }; - let last = match jobstate::last_run_time(worker_type, &store) { - Ok(time) => time, - Err(err) => { - eprintln!("could not get last run time of {} {}: {}", worker_type, store, err); - continue; - } - }; + let userid = Userid::backup_userid().clone(); - 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; + if let Err(err) = do_prune_job(job, prune_options, store.clone(), &userid, Some(event_str)) { + eprintln!("unable to start datastore prune job {} - {}", &store, err); } - }; - - let now = proxmox::tools::time::epoch_i64(); - - if next > now { continue; } - - let job = match Job::new(worker_type, &store) { - Ok(job) => job, - Err(_) => continue, // could not get lock - }; - - let userid = Userid::backup_userid().clone(); - - if let Err(err) = do_prune_job(job, prune_options, store.clone(), &userid, Some(event_str)) { - eprintln!("unable to start datastore prune job {} - {}", &store, err); } - } } @@ -476,46 +447,18 @@ async fn schedule_datastore_sync_jobs() { 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 = "syncjob"; + if check_schedule(worker_type.to_string(), event_str.clone(), job_id.clone()) { + let job = match Job::new(worker_type, &job_id) { + Ok(job) => job, + Err(_) => continue, // could not get lock + }; - 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 userid = Userid::backup_userid().clone(); - 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; + if let Err(err) = do_sync_job(job, job_config, &userid, Some(event_str)) { + eprintln!("unable to start datastore sync job {} - {}", &job_id, err); } - }; - - 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_sync_job(job, job_config, &userid, Some(event_str)) { - eprintln!("unable to start datastore sync job {} - {}", &job_id, err); } } } @@ -546,38 +489,17 @@ async fn schedule_datastore_verify_jobs() { 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; + if check_schedule(worker_type.to_string(), event_str.clone(), job_id.clone()) { + 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); } - }; - 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); } } } @@ -587,38 +509,10 @@ async fn schedule_task_log_rotate() { let worker_type = "logrotate"; let job_id = "task_archive"; - let last = match jobstate::last_run_time(worker_type, job_id) { - Ok(time) => time, - Err(err) => { - eprintln!("could not get last run time of task log archive rotation: {}", err); - return; - } - }; - // schedule daily at 00:00 like normal logrotate let schedule = "00:00"; - let event = match parse_calendar_event(schedule) { - Ok(event) => event, - Err(err) => { - // should not happen? - eprintln!("unable to parse schedule '{}' - {}", schedule, err); - return; - } - }; - - let next = match compute_next_event(&event, last, false) { - Ok(Some(next)) => next, - Ok(None) => return, - Err(err) => { - eprintln!("compute_next_event for '{}' failed - {}", schedule, err); - return; - } - }; - - let now = proxmox::tools::time::epoch_i64(); - - if next > now { + if !check_schedule(worker_type.to_string(), schedule.to_string(), job_id.to_string()) { // if we never ran the rotation, schedule instantly match jobstate::JobState::load(worker_type, job_id) { Ok(state) => match state { @@ -783,6 +677,36 @@ async fn generate_host_stats(save: bool) { }); } +fn check_schedule(worker_type: String, event_str: String, id: String) -> bool { + let event = match parse_calendar_event(&event_str) { + Ok(event) => event, + Err(err) => { + eprintln!("unable to parse schedule '{}' - {}", event_str, err); + return false; + } + }; + + let last = match jobstate::last_run_time(&worker_type, &id) { + Ok(time) => time, + Err(err) => { + eprintln!("could not get last run time of {} {}: {}", worker_type, id, err); + return false; + } + }; + + let next = match compute_next_event(&event, last, false) { + Ok(Some(next)) => next, + Ok(None) => return false, + Err(err) => { + eprintln!("compute_next_event for '{}' failed - {}", event_str, err); + return false; + } + }; + + let now = proxmox::tools::time::epoch_i64(); + next <= now +} + fn gather_disk_stats(disk_manager: Arc, path: &Path, rrd_prefix: &str, save: bool) { match proxmox_backup::tools::disks::disk_usage(path) { -- 2.20.1