public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox/proxmox-backup] add 'UTC' to calendarevent syntax
@ 2021-12-01  8:45 Dominik Csapak
  2021-12-01  8:45 ` [pbs-devel] [PATCH proxmox 1/1] proxmox-time: calendar-events: parse 'UTC' timezone into calendarevent Dominik Csapak
  2021-12-01  8:45 ` [pbs-devel] [PATCH proxmox-backup 1/1] adapt compute_next_event to new signature Dominik Csapak
  0 siblings, 2 replies; 5+ messages in thread
From: Dominik Csapak @ 2021-12-01  8:45 UTC (permalink / raw)
  To: pbs-devel

we have that in pve, so for compatibility we have to add it here too

proxmox:

Dominik Csapak (1):
  proxmox-time: calendar-events: parse 'UTC' timezone into calendarevent

 proxmox-time/src/calendar_event.rs | 25 ++++++++++++++++++++++---
 proxmox-time/src/test.rs           |  8 ++++----
 2 files changed, 26 insertions(+), 7 deletions(-)

proxmox-backup:

Dominik Csapak (1):
  adapt compute_next_event to new signature

 src/bin/proxmox-backup-proxy.rs | 4 ++--
 src/server/jobstate.rs          | 2 +-
 src/tape/inventory.rs           | 2 +-
 src/tape/media_pool.rs          | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

-- 
2.30.2





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] [PATCH proxmox 1/1] proxmox-time: calendar-events: parse 'UTC' timezone into calendarevent
  2021-12-01  8:45 [pbs-devel] [PATCH proxmox/proxmox-backup] add 'UTC' to calendarevent syntax Dominik Csapak
@ 2021-12-01  8:45 ` Dominik Csapak
  2021-12-02  9:41   ` [pbs-devel] applied: " Dietmar Maurer
  2021-12-01  8:45 ` [pbs-devel] [PATCH proxmox-backup 1/1] adapt compute_next_event to new signature Dominik Csapak
  1 sibling, 1 reply; 5+ messages in thread
From: Dominik Csapak @ 2021-12-01  8:45 UTC (permalink / raw)
  To: pbs-devel

like we do in pve. this breaks the (newly added) compute_next_event
method of CalendarEvent, but we can keep compatibilty with the
deprecated function

adapt the tests so that they add a ' UTC' by default
(so they can run reliably on any machine)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 proxmox-time/src/calendar_event.rs | 25 ++++++++++++++++++++++---
 proxmox-time/src/test.rs           |  8 ++++----
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/proxmox-time/src/calendar_event.rs b/proxmox-time/src/calendar_event.rs
index d1d74a2..efde81a 100644
--- a/proxmox-time/src/calendar_event.rs
+++ b/proxmox-time/src/calendar_event.rs
@@ -19,6 +19,8 @@ use crate::{parse_weekdays_range, TmEditor, WeekDays};
 /// specification, but are not guaranteed to be 100% compatible.
 #[derive(Default, Clone, Debug)]
 pub struct CalendarEvent {
+    /// if true, the event is calculated in utc and the local timezone otherwise
+    utc: bool,
     /// the days in a week this event should trigger
     pub(crate) days: WeekDays,
     /// the second(s) this event should trigger
@@ -38,12 +40,12 @@ pub struct CalendarEvent {
 impl CalendarEvent {
     /// Computes the next timestamp after `last`. If `utc` is false, the local
     /// timezone will be used for the calculation.
-    pub fn compute_next_event(&self, last: i64, utc: bool) -> Result<Option<i64>, Error> {
+    pub fn compute_next_event(&self, last: i64) -> Result<Option<i64>, Error> {
         let last = last + 1; // at least one second later
 
         let all_days = self.days.is_empty() || self.days.is_all();
 
-        let mut t = TmEditor::with_epoch(last, utc)?;
+        let mut t = TmEditor::with_epoch(last, self.utc)?;
 
         let mut count = 0;
 
@@ -184,7 +186,12 @@ pub fn compute_next_event(
     last: i64,
     utc: bool,
 ) -> Result<Option<i64>, Error> {
-    event.compute_next_event(last, utc)
+    if event.utc != utc {
+        let mut event = event.clone();
+        event.utc = utc;
+        return event.compute_next_event(last);
+    }
+    event.compute_next_event(last)
 }
 
 /// Parse a [CalendarEvent]
@@ -199,6 +206,10 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
     let mut has_datespec = false;
 
     let mut event = CalendarEvent::default();
+    if let Some(n) = i.strip_suffix("UTC") {
+        event.utc = true;
+        i = n.trim_end_matches(' ');
+    }
 
     if i.starts_with(|c: char| char::is_ascii_alphabetic(&c)) {
         match i {
@@ -206,6 +217,7 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
                 return Ok((
                     "",
                     CalendarEvent {
+                        utc: event.utc,
                         second: vec![DateTimeValue::Single(0)],
                         ..Default::default()
                     },
@@ -215,6 +227,7 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
                 return Ok((
                     "",
                     CalendarEvent {
+                        utc: event.utc,
                         minute: vec![DateTimeValue::Single(0)],
                         second: vec![DateTimeValue::Single(0)],
                         ..Default::default()
@@ -225,6 +238,7 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
                 return Ok((
                     "",
                     CalendarEvent {
+                        utc: event.utc,
                         hour: vec![DateTimeValue::Single(0)],
                         minute: vec![DateTimeValue::Single(0)],
                         second: vec![DateTimeValue::Single(0)],
@@ -236,6 +250,7 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
                 return Ok((
                     "",
                     CalendarEvent {
+                        utc: event.utc,
                         hour: vec![DateTimeValue::Single(0)],
                         minute: vec![DateTimeValue::Single(0)],
                         second: vec![DateTimeValue::Single(0)],
@@ -248,6 +263,7 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
                 return Ok((
                     "",
                     CalendarEvent {
+                        utc: event.utc,
                         hour: vec![DateTimeValue::Single(0)],
                         minute: vec![DateTimeValue::Single(0)],
                         second: vec![DateTimeValue::Single(0)],
@@ -260,6 +276,7 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
                 return Ok((
                     "",
                     CalendarEvent {
+                        utc: event.utc,
                         hour: vec![DateTimeValue::Single(0)],
                         minute: vec![DateTimeValue::Single(0)],
                         second: vec![DateTimeValue::Single(0)],
@@ -273,6 +290,7 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
                 return Ok((
                     "",
                     CalendarEvent {
+                        utc: event.utc,
                         hour: vec![DateTimeValue::Single(0)],
                         minute: vec![DateTimeValue::Single(0)],
                         second: vec![DateTimeValue::Single(0)],
@@ -291,6 +309,7 @@ fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent>
                 return Ok((
                     "",
                     CalendarEvent {
+                        utc: event.utc,
                         hour: vec![DateTimeValue::Single(0)],
                         minute: vec![DateTimeValue::Single(0)],
                         second: vec![DateTimeValue::Single(0)],
diff --git a/proxmox-time/src/test.rs b/proxmox-time/src/test.rs
index ec63a37..c5c23b4 100644
--- a/proxmox-time/src/test.rs
+++ b/proxmox-time/src/test.rs
@@ -18,12 +18,12 @@ const fn make_test_time(mday: i32, hour: i32, min: i32) -> i64 {
 #[test]
 fn test_compute_next_event() -> Result<(), Error> {
     let test_value = |v: &'static str, last: i64, expect: i64| -> Result<i64, Error> {
-        let event: CalendarEvent = match v.parse() {
+        let event: CalendarEvent = match format!("{} UTC", v).parse() {
             Ok(event) => event,
             Err(err) => bail!("parsing '{}' failed - {}", v, err),
         };
 
-        match event.compute_next_event(last, true) {
+        match event.compute_next_event(last) {
             Ok(Some(next)) => {
                 if next == expect {
                     println!("next {:?} => {}", event, next);
@@ -44,12 +44,12 @@ fn test_compute_next_event() -> Result<(), Error> {
     };
 
     let test_never = |v: &'static str, last: i64| -> Result<(), Error> {
-        let event: CalendarEvent = match v.parse() {
+        let event: CalendarEvent = match format!("{} UTC", v).parse() {
             Ok(event) => event,
             Err(err) => bail!("parsing '{}' failed - {}", v, err),
         };
 
-        match event.compute_next_event(last, true)? {
+        match event.compute_next_event(last)? {
             None => Ok(()),
             Some(next) => bail!(
                 "compute next for '{}' succeeded, but expected fail - result {}",
-- 
2.30.2





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] [PATCH proxmox-backup 1/1] adapt compute_next_event to new signature
  2021-12-01  8:45 [pbs-devel] [PATCH proxmox/proxmox-backup] add 'UTC' to calendarevent syntax Dominik Csapak
  2021-12-01  8:45 ` [pbs-devel] [PATCH proxmox 1/1] proxmox-time: calendar-events: parse 'UTC' timezone into calendarevent Dominik Csapak
@ 2021-12-01  8:45 ` Dominik Csapak
  2021-12-02  9:41   ` [pbs-devel] applied: " Dietmar Maurer
  1 sibling, 1 reply; 5+ messages in thread
From: Dominik Csapak @ 2021-12-01  8:45 UTC (permalink / raw)
  To: pbs-devel

the 'utc' flag is now contained in the event itself and not given
as a flag to 'compute_next_event' anymore

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/bin/proxmox-backup-proxy.rs | 4 ++--
 src/server/jobstate.rs          | 2 +-
 src/tape/inventory.rs           | 2 +-
 src/tape/media_pool.rs          | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 16ae67bb..07a53687 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -585,7 +585,7 @@ async fn schedule_datastore_garbage_collection() {
             }
         };
 
-        let next = match event.compute_next_event(last, false) {
+        let next = match event.compute_next_event(last) {
             Ok(Some(next)) => next,
             Ok(None) => continue,
             Err(err) => {
@@ -1040,7 +1040,7 @@ fn check_schedule(worker_type: &str, event_str: &str, id: &str) -> bool {
         }
     };
 
-    let next = match event.compute_next_event(last, false) {
+    let next = match event.compute_next_event(last) {
         Ok(Some(next)) => next,
         Ok(None) => return false,
         Err(err) => {
diff --git a/src/server/jobstate.rs b/src/server/jobstate.rs
index f874725a..25fb2f9b 100644
--- a/src/server/jobstate.rs
+++ b/src/server/jobstate.rs
@@ -341,7 +341,7 @@ pub fn compute_schedule_status(
     if let Some(schedule) = schedule {
         if let Ok(event) = schedule.parse::<CalendarEvent>() {
             // ignore errors
-            status.next_run = event.compute_next_event(last, false).unwrap_or(None);
+            status.next_run = event.compute_next_event(last).unwrap_or(None);
         }
     }
 
diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs
index 1f0b41f8..c76e50cd 100644
--- a/src/tape/inventory.rs
+++ b/src/tape/inventory.rs
@@ -533,7 +533,7 @@ impl Inventory {
                         set_start_time
                     }
                     MediaSetPolicy::CreateAt(ref event) => {
-                        match event.compute_next_event(set_start_time, false) {
+                        match event.compute_next_event(set_start_time) {
                             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 70713cc3..6a947b22 100644
--- a/src/tape/media_pool.rs
+++ b/src/tape/media_pool.rs
@@ -290,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)) = event.compute_next_event(set_start_time as i64, false) {
+                        if let Ok(Some(alloc_time)) = event.compute_next_event(set_start_time as i64) {
                             if current_time >= alloc_time {
                                 create_new_set = Some(String::from("policy CreateAt event triggered"));
                             }
-- 
2.30.2





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] applied: [PATCH proxmox 1/1] proxmox-time: calendar-events: parse 'UTC' timezone into calendarevent
  2021-12-01  8:45 ` [pbs-devel] [PATCH proxmox 1/1] proxmox-time: calendar-events: parse 'UTC' timezone into calendarevent Dominik Csapak
@ 2021-12-02  9:41   ` Dietmar Maurer
  0 siblings, 0 replies; 5+ messages in thread
From: Dietmar Maurer @ 2021-12-02  9:41 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup 1/1] adapt compute_next_event to new signature
  2021-12-01  8:45 ` [pbs-devel] [PATCH proxmox-backup 1/1] adapt compute_next_event to new signature Dominik Csapak
@ 2021-12-02  9:41   ` Dietmar Maurer
  0 siblings, 0 replies; 5+ messages in thread
From: Dietmar Maurer @ 2021-12-02  9:41 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-02  9:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01  8:45 [pbs-devel] [PATCH proxmox/proxmox-backup] add 'UTC' to calendarevent syntax Dominik Csapak
2021-12-01  8:45 ` [pbs-devel] [PATCH proxmox 1/1] proxmox-time: calendar-events: parse 'UTC' timezone into calendarevent Dominik Csapak
2021-12-02  9:41   ` [pbs-devel] applied: " Dietmar Maurer
2021-12-01  8:45 ` [pbs-devel] [PATCH proxmox-backup 1/1] adapt compute_next_event to new signature Dominik Csapak
2021-12-02  9:41   ` [pbs-devel] applied: " Dietmar Maurer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal