11use log:: debug;
22use reqwest:: header:: { HeaderMap , HeaderValue } ;
33use serde_json:: { json, Value } ;
4- use std:: { sync:: Mutex , time:: Duration , time :: Instant } ;
4+ use std:: { sync:: Mutex , time:: Duration } ;
55use time:: { format_description:: well_known:: Rfc3339 , OffsetDateTime } ;
66use uuid:: Uuid ;
77
@@ -16,14 +16,14 @@ static HTTP_REQUEST_TIMEOUT: Duration = Duration::from_secs(10);
1616#[ derive( Debug , Clone ) ]
1717pub struct TrackingSession {
1818 pub id : String ,
19- pub last_touch_ts : Instant ,
19+ pub last_touch_ts : OffsetDateTime ,
2020}
2121
2222impl TrackingSession {
2323 fn new ( ) -> Self {
2424 TrackingSession {
2525 id : Uuid :: new_v4 ( ) . to_string ( ) ,
26- last_touch_ts : Instant :: now ( ) ,
26+ last_touch_ts : OffsetDateTime :: now_utc ( ) ,
2727 }
2828 }
2929}
@@ -66,11 +66,11 @@ impl AptabaseClient {
6666 pub ( crate ) fn eval_session_id ( & self ) -> String {
6767 let mut session = self . session . lock ( ) . expect ( "could not lock session" ) ;
6868
69- // session timeout since last touched, start a new one!
70- if session. last_touch_ts . elapsed ( ) > SESSION_TIMEOUT {
71- * session = TrackingSession :: new ( )
69+ let now = OffsetDateTime :: now_utc ( ) ;
70+ if ( now - session. last_touch_ts ) > SESSION_TIMEOUT {
71+ * session = TrackingSession :: new ( ) ;
7272 } else {
73- session. last_touch_ts = Instant :: now ( )
73+ session. last_touch_ts = now;
7474 }
7575 return session. id . clone ( ) ;
7676 }
0 commit comments