From 5b3ba8def5d25d8537e260ab678e0d9c0cff1a7a Mon Sep 17 00:00:00 2001 From: rupakkorde Date: Thu, 17 Oct 2024 17:50:31 +0530 Subject: [PATCH] lts/enh/reducing-delay-in-sending-lts-trigger-fcm-for-new-ride --- crates/location_tracking_service/src/common/types.rs | 1 + .../src/domain/action/internal/location.rs | 1 + .../src/domain/action/ui/location.rs | 9 ++++++++- crates/location_tracking_service/src/environment.rs | 4 ++++ crates/location_tracking_service/src/redis/commands.rs | 2 ++ dhall-configs/dev/location_tracking_service.dhall | 1 + 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/location_tracking_service/src/common/types.rs b/crates/location_tracking_service/src/common/types.rs index fe61739c..1084e005 100644 --- a/crates/location_tracking_service/src/common/types.rs +++ b/crates/location_tracking_service/src/common/types.rs @@ -201,6 +201,7 @@ pub struct DriverAllDetails { pub driver_last_known_location: DriverLastKnownLocation, pub blocked_till: Option, pub stop_detection: Option, + pub ride_status: Option, // pub travelled_distance: Option, } diff --git a/crates/location_tracking_service/src/domain/action/internal/location.rs b/crates/location_tracking_service/src/domain/action/internal/location.rs index f3c491c2..90f3cfc6 100644 --- a/crates/location_tracking_service/src/domain/action/internal/location.rs +++ b/crates/location_tracking_service/src/domain/action/internal/location.rs @@ -200,6 +200,7 @@ pub async fn driver_block_till( &details.driver_last_known_location.timestamp, &Some(request_body.block_till), details.stop_detection, + &None::, // travelled_distance.to_owned(), ) .await?; diff --git a/crates/location_tracking_service/src/domain/action/ui/location.rs b/crates/location_tracking_service/src/domain/action/ui/location.rs index c33b15f2..425c5743 100644 --- a/crates/location_tracking_service/src/domain/action/ui/location.rs +++ b/crates/location_tracking_service/src/domain/action/ui/location.rs @@ -361,6 +361,7 @@ async fn process_driver_locations( &latest_driver_location_ts, &None::, stop_detection, + &driver_ride_status, // travelled_distance.to_owned(), ) .await?; @@ -497,7 +498,13 @@ pub async fn track_driver_location( .await? .ok_or(AppError::DriverLastKnownLocationNotFound)?; - let delay_time = Utc::now().timestamp() - data.driver_location_delay_in_sec; + let delay_time = match driver_location_details.ride_status { + Some(RideStatus::NEW) => { + Utc::now().timestamp() - data.driver_location_delay_for_new_ride_sec + } + _ => Utc::now().timestamp() - data.driver_location_delay_in_sec, + }; + let TimeStamp(driver_update_time) = driver_location_details.driver_last_known_location.timestamp; if driver_update_time.timestamp() < delay_time { diff --git a/crates/location_tracking_service/src/environment.rs b/crates/location_tracking_service/src/environment.rs index c05eb457..ead78035 100644 --- a/crates/location_tracking_service/src/environment.rs +++ b/crates/location_tracking_service/src/environment.rs @@ -50,6 +50,7 @@ pub struct AppConfig { pub log_unprocessible_req_body: Vec, pub max_allowed_req_size: usize, pub driver_location_delay_in_sec: i64, + pub driver_location_delay_for_new_ride_sec: i64, pub trigger_fcm_callback_url: String, pub apns_url: String, } @@ -119,6 +120,7 @@ pub struct AppState { pub log_unprocessible_req_body: Vec, pub request_timeout: u64, pub driver_location_delay_in_sec: i64, + pub driver_location_delay_for_new_ride_sec: i64, pub trigger_fcm_callback_url: Url, pub apns_url: Url, } @@ -225,6 +227,8 @@ impl AppState { blacklist_merchants, stop_detection: app_config.stop_detection, driver_location_delay_in_sec: app_config.driver_location_delay_in_sec, + driver_location_delay_for_new_ride_sec: app_config + .driver_location_delay_for_new_ride_sec, trigger_fcm_callback_url: Url::parse(app_config.trigger_fcm_callback_url.as_str()) .expect("Failed to parse fcm_callback_url."), apns_url: Url::parse(app_config.apns_url.as_str()).expect("Failed to parse apns_url."), diff --git a/crates/location_tracking_service/src/redis/commands.rs b/crates/location_tracking_service/src/redis/commands.rs index 88b631a3..24fd54de 100644 --- a/crates/location_tracking_service/src/redis/commands.rs +++ b/crates/location_tracking_service/src/redis/commands.rs @@ -301,6 +301,7 @@ pub async fn set_driver_last_location_update( last_location_ts: &TimeStamp, blocked_till: &Option, stop_detection: Option, + ride_status: &Option, ) -> Result { let last_known_location = DriverLastKnownLocation { location: Point { @@ -315,6 +316,7 @@ pub async fn set_driver_last_location_update( driver_last_known_location: last_known_location.to_owned(), blocked_till: blocked_till.to_owned(), stop_detection, + ride_status: ride_status.to_owned(), // travelled_distance: Some(travelled_distance), }; diff --git a/dhall-configs/dev/location_tracking_service.dhall b/dhall-configs/dev/location_tracking_service.dhall index 082f9948..fe2bb6c7 100644 --- a/dhall-configs/dev/location_tracking_service.dhall +++ b/dhall-configs/dev/location_tracking_service.dhall @@ -71,6 +71,7 @@ in { log_unprocessible_req_body = ["UNPROCESSIBLE_REQUEST", "REQUEST_TIMEOUT", "LARGE_PAYLOAD_SIZE", "HITS_LIMIT_EXCEEDED"], max_allowed_req_size = 512000, -- 500 KB driver_location_delay_in_sec = 60, + driver_location_delay_for_new_ride_sec = 10, trigger_fcm_callback_url = "http://127.0.0.1:8016/internal/driverInactiveFCM", apns_url = "https://api.sandbox.push.apple.com:443", } \ No newline at end of file