From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
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 5BF4682877
 for <pbs-devel@lists.proxmox.com>; Tue, 30 Nov 2021 13:13:13 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 6134726A42
 for <pbs-devel@lists.proxmox.com>; Tue, 30 Nov 2021 13:12:19 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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 1CF0A2693A
 for <pbs-devel@lists.proxmox.com>; Tue, 30 Nov 2021 13:12:13 +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 EC55D449EE
 for <pbs-devel@lists.proxmox.com>; Tue, 30 Nov 2021 13:12:12 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue, 30 Nov 2021 13:12:09 +0100
Message-Id: <20211130121209.216846-16-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20211130121209.216846-1-d.csapak@proxmox.com>
References: <20211130121209.216846-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.183 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 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. [jobstate.rs, proxmox-backup-proxy.rs, inventory.rs]
Subject: [pbs-devel] [PATCH proxmox-backup 1/1] remove use of deprecated
 functions from proxmox-time
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 30 Nov 2021 12:13:13 -0000

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 pbs-api-types/src/tape/media_pool.rs |  6 +++---
 src/bin/proxmox-backup-proxy.rs      | 10 +++++-----
 src/server/jobstate.rs               |  6 +++---
 src/tape/inventory.rs                |  3 +--
 src/tape/media_pool.rs               |  3 +--
 src/tape/test/compute_media_state.rs |  4 ++--
 6 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/pbs-api-types/src/tape/media_pool.rs b/pbs-api-types/src/tape/media_pool.rs
index 3b1cb0f5..c0cba2bd 100644
--- a/pbs-api-types/src/tape/media_pool.rs
+++ b/pbs-api-types/src/tape/media_pool.rs
@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
 
 use proxmox_schema::{api, Schema, StringSchema, ApiStringFormat, Updater};
 
-use proxmox_time::{parse_calendar_event, parse_time_span, CalendarEvent, TimeSpan};
+use proxmox_time::{CalendarEvent, TimeSpan};
 
 use crate::{
     PROXMOX_SAFE_ID_FORMAT,
@@ -62,7 +62,7 @@ impl std::str::FromStr for MediaSetPolicy {
             return Ok(MediaSetPolicy::AlwaysCreate);
         }
 
-        let event = parse_calendar_event(s)?;
+        let event = s.parse()?;
 
         Ok(MediaSetPolicy::CreateAt(event))
     }
@@ -97,7 +97,7 @@ impl std::str::FromStr for RetentionPolicy {
             return Ok(RetentionPolicy::KeepForever);
         }
 
-        let time_span = parse_time_span(s)?;
+        let time_span = s.parse()?;
 
         Ok(RetentionPolicy::ProtectFor(time_span))
     }
diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 0d852a7a..16ae67bb 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -47,7 +47,7 @@ use proxmox_backup::{
 };
 
 use pbs_buildcfg::configdir;
-use proxmox_time::{compute_next_event, parse_calendar_event};
+use proxmox_time::CalendarEvent;
 
 use pbs_api_types::{
     Authid, TapeBackupJobConfig, VerificationJobConfig, SyncJobConfig, DataStoreConfig,
@@ -565,7 +565,7 @@ async fn schedule_datastore_garbage_collection() {
             None => continue,
         };
 
-        let event = match parse_calendar_event(&event_str) {
+        let event: CalendarEvent = match event_str.parse() {
             Ok(event) => event,
             Err(err) => {
                 eprintln!("unable to parse schedule '{}' - {}", event_str, err);
@@ -585,7 +585,7 @@ async fn schedule_datastore_garbage_collection() {
             }
         };
 
-        let next = match compute_next_event(&event, last, false) {
+        let next = match event.compute_next_event(last, false) {
             Ok(Some(next)) => next,
             Ok(None) => continue,
             Err(err) => {
@@ -1024,7 +1024,7 @@ fn generate_host_stats_sync() {
 }
 
 fn check_schedule(worker_type: &str, event_str: &str, id: &str) -> bool {
-    let event = match parse_calendar_event(event_str) {
+    let event: CalendarEvent = match event_str.parse() {
         Ok(event) => event,
         Err(err) => {
             eprintln!("unable to parse schedule '{}' - {}", event_str, err);
@@ -1040,7 +1040,7 @@ fn check_schedule(worker_type: &str, event_str: &str, id: &str) -> bool {
         }
     };
 
-    let next = match compute_next_event(&event, last, false) {
+    let next = match event.compute_next_event(last, false) {
         Ok(Some(next)) => next,
         Ok(None) => return false,
         Err(err) => {
diff --git a/src/server/jobstate.rs b/src/server/jobstate.rs
index adb1bbe2..f874725a 100644
--- a/src/server/jobstate.rs
+++ b/src/server/jobstate.rs
@@ -46,7 +46,7 @@ use proxmox_sys::fs::{
     create_path, file_read_optional_string, replace_file, CreateOptions,
 };
 
-use proxmox_time::{compute_next_event, parse_calendar_event};
+use proxmox_time::CalendarEvent;
 
 use pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR_M;
 use pbs_config::{open_backup_lockfile, BackupLockGuard};
@@ -339,9 +339,9 @@ pub fn compute_schedule_status(
     status.last_run_endtime = endtime;
 
     if let Some(schedule) = schedule {
-        if let Ok(event) = parse_calendar_event(&schedule) {
+        if let Ok(event) = schedule.parse::<CalendarEvent>() {
             // ignore errors
-            status.next_run = compute_next_event(&event, last, false).unwrap_or(None);
+            status.next_run = event.compute_next_event(last, false).unwrap_or(None);
         }
     }
 
diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs
index 4ecbb425..1f0b41f8 100644
--- a/src/tape/inventory.rs
+++ b/src/tape/inventory.rs
@@ -33,7 +33,6 @@ use serde_json::json;
 use proxmox_sys::fs::{replace_file, file_get_json, CreateOptions};
 use proxmox_uuid::Uuid;
 
-use proxmox_time::compute_next_event;
 use pbs_config::BackupLockGuard;
 use pbs_api_types::{MediaSetPolicy, RetentionPolicy, MediaStatus, MediaLocation};
 
@@ -534,7 +533,7 @@ impl Inventory {
                         set_start_time
                     }
                     MediaSetPolicy::CreateAt(ref event) => {
-                        match compute_next_event(event, set_start_time, false) {
+                        match event.compute_next_event(set_start_time, false) {
                             Ok(Some(next)) => next,
                             Ok(None) | Err(_) => return i64::MAX,
                         }
diff --git a/src/tape/media_pool.rs b/src/tape/media_pool.rs
index 68908768..70713cc3 100644
--- a/src/tape/media_pool.rs
+++ b/src/tape/media_pool.rs
@@ -18,7 +18,6 @@ use pbs_api_types::{
     Fingerprint, MediaStatus, MediaLocation, MediaSetPolicy, RetentionPolicy,
     MediaPoolConfig,
 };
-use proxmox_time::compute_next_event;
 use pbs_config::BackupLockGuard;
 
 use crate::tape::{
@@ -291,7 +290,7 @@ impl MediaPool {
                 }
                 MediaSetPolicy::CreateAt(event) => {
                     if let Some(set_start_time) = self.inventory.media_set_start_time(&self.current_media_set.uuid()) {
-                        if let Ok(Some(alloc_time)) = compute_next_event(event, set_start_time as i64, false) {
+                        if let Ok(Some(alloc_time)) = event.compute_next_event(set_start_time as i64, false) {
                             if current_time >= alloc_time {
                                 create_new_set = Some(String::from("policy CreateAt event triggered"));
                             }
diff --git a/src/tape/test/compute_media_state.rs b/src/tape/test/compute_media_state.rs
index c1dfdba7..78e32190 100644
--- a/src/tape/test/compute_media_state.rs
+++ b/src/tape/test/compute_media_state.rs
@@ -100,8 +100,8 @@ fn test_media_expire_time() -> Result<(), Error> {
     let sl2= MediaSetLabel::with_data("p1", Uuid::generate(), 0, ctime + 120, None);
     let tape2_uuid = inventory.generate_used_tape("tape2", sl2, 0);
 
-    let event = proxmox_time::parse_calendar_event("*:0/2")?;
-    let span = proxmox_time::parse_time_span("120 seconds")?;
+    let event = "*:0/2".parse()?;
+    let span = "120 seconds".parse()?;
 
     let pool = MediaPool::new(
         "p1",
-- 
2.30.2