From 592c4c006974c0d55185e2e92ddc965f690ee55e Mon Sep 17 00:00:00 2001 From: Stefan Kroboth Date: Thu, 23 Feb 2023 14:36:44 +0100 Subject: [PATCH] Compute runtime when adding stop_time to record in pyauditor --- pyauditor/src/domain/record.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pyauditor/src/domain/record.rs b/pyauditor/src/domain/record.rs index ef008bb1..a83bbb54 100644 --- a/pyauditor/src/domain/record.rs +++ b/pyauditor/src/domain/record.rs @@ -113,6 +113,9 @@ impl Record { let stop_time: NaiveDateTime = stop_time.extract()?; let stop_time = Utc.from_utc_datetime(&stop_time.into()); self_.inner.stop_time = Some(stop_time); + if let Some(start_time) = self_.inner.start_time.as_ref() { + self_.inner.runtime = Some((stop_time - *start_time).num_seconds()) + } Ok(self_) } @@ -161,19 +164,10 @@ impl Record { /// Returns the runtime of a record. #[getter] - fn get_runtime(&self) -> Option { + fn runtime(&self) -> Option { self.inner.runtime } - /// Set runtime of a record. - /// - /// Note: Should only be used for mocking records received from an Auditor instance. - #[setter] - fn set_runtime(&mut self, value: i64) -> PyResult<()> { - self.inner.runtime = Some(value); - Ok(()) - } - /// Output content of Record as JSON-encoded string fn to_json(&self) -> Result { Ok(format!("{}", serde_json::to_value(&self.inner)?))