From 95cac4dfb9a1edf31052892497e2140ebc5a1622 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 25 Apr 2020 01:37:56 +0200 Subject: [PATCH] add context-uptime to dc_get_info() --- src/context.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/context.rs b/src/context.rs index 113860431..0be974ae2 100644 --- a/src/context.rs +++ b/src/context.rs @@ -21,6 +21,7 @@ use crate::message::{self, Message, MessengerMessage, MsgId}; use crate::param::Params; use crate::smtp::Smtp; use crate::sql::Sql; +use std::time::Instant; /// Callback function type for [Context] /// @@ -57,6 +58,7 @@ pub struct Context { /// Mutex to avoid generating the key for the user more than once. pub generating_key_mutex: Mutex<()>, pub translated_stockstrings: RwLock>, + creation_time: Instant, } #[derive(Debug, PartialEq, Eq)] @@ -138,6 +140,7 @@ impl Context { perform_inbox_jobs_needed: Arc::new(RwLock::new(false)), generating_key_mutex: Mutex::new(()), translated_stockstrings: RwLock::new(HashMap::new()), + creation_time: std::time::Instant::now(), }; ensure!( @@ -311,6 +314,12 @@ impl Context { ); res.insert("fingerprint", fingerprint_str); + let elapsed = self.creation_time.elapsed().as_secs(); + let hours = elapsed / 3600; + let minutes = elapsed % 3600 / 60; + let seconds = elapsed % 3600 % 60; + res.insert("uptime", format!("{}h {}m {}s", hours, minutes, seconds)); + res }