From 130ce8e1959868296156ecf9a013a4bdafb0553f Mon Sep 17 00:00:00 2001 From: Sarthak Soni Date: Fri, 20 Dec 2024 16:04:15 +0530 Subject: [PATCH] chore: Resolved comments --- .github/CODEOWNERS | 5 ++++ crates/router/src/core/routing.rs | 47 +++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index dc4010d0fd0c..e3027171a5f6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -66,6 +66,11 @@ crates/router/src/core/routing @juspay/hyperswitch-routing crates/router/src/core/routing.rs @juspay/hyperswitch-routing crates/router/src/core/payments/routing @juspay/hyperswitch-routing crates/router/src/core/payments/routing.rs @juspay/hyperswitch-routing +crates/external_services/src/grpc_client/dynamic_routing.rs @juspay/hyperswitch-routing +crates/external_services/src/grpc_client/dynamic_routing/contract_routing_client.rs @juspay/hyperswitch-routing +crates/external_services/src/grpc_client/dynamic_routing/elimination_rate_client.rs @juspay/hyperswitch-routing +crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs @juspay/hyperswitch-routing +crates/external_services/src/grpc_client/health_check_client.rs @juspay/hyperswitch-routing crates/api_models/src/payment_methods.rs @juspay/hyperswitch-routing crates/router/src/core/payment_methods.rs @juspay/hyperswitch-routing diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs index 897dc7952217..82efa9efeda4 100644 --- a/crates/router/src/core/routing.rs +++ b/crates/router/src/core/routing.rs @@ -448,7 +448,6 @@ pub async fn link_routing_config( )? .unwrap_or_default(); - // Need to add contract based routing here utils::when( matches!( dynamic_routing_ref.success_based_algorithm, @@ -470,6 +469,16 @@ pub async fn link_routing_config( }, enabled_feature: _ }) if id == &algorithm_id + ) || matches!( + dynamic_routing_ref.contract_based_routing, + Some(routing::ContractRoutingAlgorithm { + algorithm_id_with_timestamp: + routing_types::DynamicAlgorithmWithTimestamp { + algorithm_id: Some(ref id), + timestamp: _ + }, + enabled_feature: _ + }) if id == &algorithm_id ), || { Err(errors::ApiErrorResponse::PreconditionFailed { @@ -478,7 +487,12 @@ pub async fn link_routing_config( }, )?; - dynamic_routing_ref.update_algorithm_id( + println!("algo is - {:?}", routing_algorithm.algorithm_data.clone()); + + // These checks would be Expensive + // A better way to do this would be to have some typed information in the algorithm_data + if &routing_algorithm.name == helpers::SUCCESS_BASED_DYNAMIC_ROUTING_ALGORITHM { + dynamic_routing_ref.update_algorithm_id( algorithm_id, dynamic_routing_ref .success_based_algorithm @@ -490,6 +504,35 @@ pub async fn link_routing_config( .enabled_feature, routing_types::DynamicRoutingType::SuccessRateBasedRouting, ); + } else if &routing_algorithm.name + == helpers::ELIMINATION_BASED_DYNAMIC_ROUTING_ALGORITHM + { + dynamic_routing_ref.update_algorithm_id( + algorithm_id, + dynamic_routing_ref + .elimination_routing_algorithm + .clone() + .ok_or(errors::ApiErrorResponse::InternalServerError) + .attach_printable( + "missing elimination_routing_algorithm in dynamic_algorithm_ref from business_profile table", + )? + .enabled_feature, + routing_types::DynamicRoutingType::EliminationRouting, + ); + } else if &routing_algorithm.name == helpers::CONTRACT_BASED_DYNAMIC_ROUTING_ALGORITHM { + dynamic_routing_ref.update_algorithm_id( + algorithm_id, + dynamic_routing_ref + .contract_based_routing + .clone() + .ok_or(errors::ApiErrorResponse::InternalServerError) + .attach_printable( + "missing contract_based_routing in dynamic_algorithm_ref from business_profile table", + )? + .enabled_feature, + routing_types::DynamicRoutingType::ContractBasedRouting, + ); + } helpers::update_business_profile_active_dynamic_algorithm_ref( db,