[pbs-devel] [PATCH proxmox-backup 1/1] remove use of deprecated functions from proxmox-time

Dominik Csapak d.csapak at proxmox.com
Tue Nov 30 13:12:09 CET 2021


Signed-off-by: Dominik Csapak <d.csapak at 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






More information about the pbs-devel mailing list