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 BDF4960B3E for ; Thu, 3 Sep 2020 13:40:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B83A218643 for ; Thu, 3 Sep 2020 13:40:07 +0200 (CEST) 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 7B03618546 for ; Thu, 3 Sep 2020 13:40:02 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 383F3449FC for ; Thu, 3 Sep 2020 13:40:02 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 3 Sep 2020 13:39:53 +0200 Message-Id: <20200903114000.6932-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903114000.6932-1-d.csapak@proxmox.com> References: <20200903114000.6932-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.083 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records 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_NONE 0.001 SPF: sender does not publish an 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. [sync.rs, proxmox-backup-proxy.rs, time.rs] Subject: [pbs-devel] [PATCH proxmox-backup 03/10] tools/systemd/time: convert the resulting timestamp into an option 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, 03 Sep 2020 11:40:07 -0000 we want to use dates for the calendarspec, and with that there are some impossible combinations that cannot be detected during parsing (e.g. some datetimes do not exist in some timezones, and the timezone can change after setting the schedule) so finding no timestamp is not an error anymore but a valid result we omit logging in that case (since it is not an error anymore) Signed-off-by: Dominik Csapak --- src/api2/admin/sync.rs | 3 ++- src/bin/proxmox-backup-proxy.rs | 9 ++++++--- src/tools/systemd/time.rs | 16 ++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/api2/admin/sync.rs b/src/api2/admin/sync.rs index ff1e5ebf..bea52a0a 100644 --- a/src/api2/admin/sync.rs +++ b/src/api2/admin/sync.rs @@ -57,7 +57,8 @@ pub fn list_sync_jobs( job.next_run = (|| -> Option { let schedule = job.schedule.as_ref()?; let event = parse_calendar_event(&schedule).ok()?; - compute_next_event(&event, last, false).ok() + // ignore errors + compute_next_event(&event, last, false).unwrap_or_else(|_| None) })(); } diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index dd081dfe..2b43c5ac 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -301,7 +301,8 @@ async fn schedule_datastore_garbage_collection() { }; let next = match compute_next_event(&event, last, false) { - Ok(next) => next, + Ok(Some(next)) => next, + Ok(None) => continue, Err(err) => { eprintln!("compute_next_event for '{}' failed - {}", event_str, err); continue; @@ -412,7 +413,8 @@ async fn schedule_datastore_prune() { }; let next = match compute_next_event(&event, last, false) { - Ok(next) => next, + Ok(Some(next)) => next, + Ok(None) => continue, Err(err) => { eprintln!("compute_next_event for '{}' failed - {}", event_str, err); continue; @@ -520,7 +522,8 @@ async fn schedule_datastore_sync_jobs() { }; let next = match compute_next_event(&event, last, false) { - Ok(next) => next, + Ok(Some(next)) => next, + Ok(None) => continue, Err(err) => { eprintln!("compute_next_event for '{}' failed - {}", event_str, err); continue; diff --git a/src/tools/systemd/time.rs b/src/tools/systemd/time.rs index a6db8a92..6c7cefec 100644 --- a/src/tools/systemd/time.rs +++ b/src/tools/systemd/time.rs @@ -1,4 +1,4 @@ -use anyhow::{bail, Error}; +use anyhow::Error; use bitflags::bitflags; pub use super::parse_time::*; @@ -155,7 +155,7 @@ pub fn compute_next_event( event: &CalendarEvent, last: i64, utc: bool, -) -> Result { +) -> Result, Error> { let last = last + 1; // at least one second later @@ -166,8 +166,9 @@ pub fn compute_next_event( let mut count = 0; loop { - if count > 1000 { // should not happen - bail!("unable to compute next calendar event"); + // cancel after 1000 loops + if count > 1000 { + return Ok(None); } else { count += 1; } @@ -243,13 +244,15 @@ pub fn compute_next_event( } let next = t.into_epoch()?; - return Ok(next) + return Ok(Some(next)) } } #[cfg(test)] mod test { + use anyhow::bail; + use super::*; use proxmox::tools::time::*; @@ -276,7 +279,7 @@ mod test { }; match compute_next_event(&event, last, true) { - Ok(next) => { + Ok(Some(next)) => { if next == expect { println!("next {:?} => {}", event, next); } else { @@ -284,6 +287,7 @@ mod test { event, gmtime(next), gmtime(expect)); } } + Ok(None) => bail!("next {:?} failed to find a timestamp", event), Err(err) => bail!("compute next for '{}' failed - {}", v, err), } -- 2.20.1