From 4aa8f783cfe34505aac3a91da697c851aee901ea Mon Sep 17 00:00:00 2001 From: Tim Bruijnzeels Date: Tue, 2 Nov 2021 10:09:15 +0100 Subject: [PATCH] Report correct next update times (#701) --- src/commons/api/ca.rs | 54 ++++++++++++++++++----------- src/daemon/ca/manager.rs | 16 +++++++-- src/daemon/ca/publishing.rs | 69 +++++++++++++++++++++++++------------ src/daemon/ca/status.rs | 15 +++++--- 4 files changed, 104 insertions(+), 50 deletions(-) diff --git a/src/commons/api/ca.rs b/src/commons/api/ca.rs index 6a9b8692..da7fead9 100644 --- a/src/commons/api/ca.rs +++ b/src/commons/api/ca.rs @@ -1412,17 +1412,17 @@ impl ParentStatus { self.last_exchange.as_ref().map(|e| e.to_failure_opt()).flatten() } - fn set_next_exchange_plus_seconds(&mut self, next_seconds: i64) { - self.next_exchange_before += Duration::seconds(next_seconds); + fn set_next_exchange(&mut self, next_run_seconds: i64) { + self.next_exchange_before = Timestamp::now_plus_seconds(next_run_seconds); } - fn set_failure(&mut self, uri: ServiceUri, error: ErrorResponse, next_seconds: i64) { + fn set_failure(&mut self, uri: ServiceUri, error: ErrorResponse, next_run_seconds: i64) { self.last_exchange = Some(ParentExchange { timestamp: Timestamp::now(), uri, result: ExchangeResult::Failure(error), }); - self.set_next_exchange_plus_seconds(next_seconds); + self.set_next_exchange(next_run_seconds); } fn set_entitlements(&mut self, uri: ServiceUri, entitlements: &Entitlements, next_run_seconds: i64) { @@ -1444,7 +1444,7 @@ impl ParentStatus { } self.all_resources = all_resources; - self.set_next_exchange_plus_seconds(next_run_seconds); + self.set_next_exchange(next_run_seconds); } fn set_last_updated(&mut self, uri: ServiceUri, next_run_seconds: i64) { @@ -1455,7 +1455,7 @@ impl ParentStatus { result: ExchangeResult::Success, }); self.last_success = Some(timestamp); - self.set_next_exchange_plus_seconds(next_run_seconds); + self.set_next_exchange(next_run_seconds); } } @@ -1521,7 +1521,7 @@ impl RepoStatus { self.next_exchange_before = timestamp.plus_minutes(5); } - pub fn set_published(&mut self, uri: ServiceUri, published: Vec, next_hours: i64) { + pub fn set_published(&mut self, uri: ServiceUri, published: Vec, next_update: Timestamp) { let timestamp = Timestamp::now(); self.last_exchange = Some(ParentExchange { timestamp, @@ -1530,10 +1530,10 @@ impl RepoStatus { }); self.published = published; self.last_success = Some(timestamp); - self.next_exchange_before = timestamp.plus_hours(next_hours); + self.next_exchange_before = next_update; } - pub fn set_last_updated(&mut self, uri: ServiceUri, next_hours: i64) { + pub fn set_last_updated(&mut self, uri: ServiceUri, next_update: Timestamp) { let timestamp = Timestamp::now(); self.last_exchange = Some(ParentExchange { timestamp, @@ -1541,7 +1541,7 @@ impl RepoStatus { result: ExchangeResult::Success, }); self.last_success = Some(timestamp); - self.next_exchange_before = timestamp.plus_hours(next_hours); + self.next_exchange_before = next_update; } } @@ -1844,18 +1844,10 @@ impl Timestamp { Timestamp::now().minus_hours(hours) } - pub fn now_minus_seconds(seconds: i64) -> Self { - Timestamp::now().minus_seconds(seconds) - } - pub fn minus_hours(self, hours: i64) -> Self { self - Duration::hours(hours) } - pub fn minus_seconds(self, seconds: i64) -> Self { - self - Duration::seconds(seconds) - } - pub fn now_plus_minutes(minutes: i64) -> Self { Timestamp::now().plus_minutes(minutes) } @@ -1864,8 +1856,24 @@ impl Timestamp { self + Duration::minutes(minutes) } - pub fn to_rfc3339(&self) -> String { - Time::from(*self).to_rfc3339() + pub fn minus_seconds(self, seconds: i64) -> Self { + self - Duration::seconds(seconds) + } + + pub fn plus_seconds(self, seconds: i64) -> Self { + self - Duration::seconds(seconds) + } + + pub fn now_minus_seconds(seconds: i64) -> Self { + Timestamp::now().minus_seconds(seconds) + } + + pub fn now_plus_seconds(seconds: i64) -> Self { + Timestamp::now().plus_seconds(seconds) + } + + pub fn to_rfc3339(self) -> String { + Time::from(self).to_rfc3339() } } @@ -1875,6 +1883,12 @@ impl From for Time { } } +impl From