add context-uptime to dc_get_info()

This commit is contained in:
B. Petersen
2020-04-25 01:37:56 +02:00
parent 3d6ca973c4
commit 95cac4dfb9

View File

@@ -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<HashMap<usize, String>>,
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
}