mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
feat: add metrics to drainer (#497)
This commit is contained in:
@ -13,7 +13,7 @@ pub mod validation;
|
||||
|
||||
/// Date-time utilities.
|
||||
pub mod date_time {
|
||||
use time::{OffsetDateTime, PrimitiveDateTime};
|
||||
use time::{Instant, OffsetDateTime, PrimitiveDateTime};
|
||||
/// Struct to represent milliseconds in time sensitive data fields
|
||||
#[derive(Debug)]
|
||||
pub struct Milliseconds(i32);
|
||||
@ -33,6 +33,15 @@ pub mod date_time {
|
||||
pub fn now_unix_timestamp() -> i64 {
|
||||
OffsetDateTime::now_utc().unix_timestamp()
|
||||
}
|
||||
|
||||
/// Calculate execution time for a async block in milliseconds
|
||||
pub async fn time_it<T, Fut: futures::Future<Output = T>, F: FnOnce() -> Fut>(
|
||||
block: F,
|
||||
) -> (T, f64) {
|
||||
let start = Instant::now();
|
||||
let result = block().await;
|
||||
(result, start.elapsed().as_seconds_f64() * 1000f64)
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a nanoid with the given prefix and length
|
||||
|
||||
Reference in New Issue
Block a user