mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(routing): Add support to update config for elimination routing (#7938)
Co-authored-by: Spriti Aneja <spriti.aneja@juspay.in> Co-authored-by: Gnanasundari24 <118818938+Gnanasundari24@users.noreply.github.com>
This commit is contained in:
@ -2,9 +2,10 @@ use common_utils::events::{ApiEventMetric, ApiEventsType};
|
||||
|
||||
use crate::routing::{
|
||||
ContractBasedRoutingPayloadWrapper, ContractBasedRoutingSetupPayloadWrapper,
|
||||
DynamicRoutingUpdateConfigQuery, LinkedRoutingConfigRetrieveResponse, MerchantRoutingAlgorithm,
|
||||
ProfileDefaultRoutingConfig, RoutingAlgorithmId, RoutingConfigRequest, RoutingDictionaryRecord,
|
||||
RoutingKind, RoutingLinkWrapper, RoutingPayloadWrapper, RoutingRetrieveLinkQuery,
|
||||
DynamicRoutingUpdateConfigQuery, EliminationRoutingPayloadWrapper,
|
||||
LinkedRoutingConfigRetrieveResponse, MerchantRoutingAlgorithm, ProfileDefaultRoutingConfig,
|
||||
RoutingAlgorithmId, RoutingConfigRequest, RoutingDictionaryRecord, RoutingKind,
|
||||
RoutingLinkWrapper, RoutingPayloadWrapper, RoutingRetrieveLinkQuery,
|
||||
RoutingRetrieveLinkQueryWrapper, RoutingRetrieveQuery, RoutingVolumeSplitWrapper,
|
||||
SuccessBasedRoutingConfig, SuccessBasedRoutingPayloadWrapper, ToggleDynamicRoutingQuery,
|
||||
ToggleDynamicRoutingWrapper,
|
||||
@ -98,6 +99,12 @@ impl ApiEventMetric for SuccessBasedRoutingPayloadWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiEventMetric for EliminationRoutingPayloadWrapper {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Routing)
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiEventMetric for ContractBasedRoutingPayloadWrapper {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Routing)
|
||||
|
||||
@ -839,18 +839,42 @@ pub struct EliminationAnalyserConfig {
|
||||
pub bucket_leak_interval_in_secs: Option<u64>,
|
||||
}
|
||||
|
||||
impl EliminationAnalyserConfig {
|
||||
pub fn update(&mut self, new: Self) {
|
||||
if let Some(bucket_size) = new.bucket_size {
|
||||
self.bucket_size = Some(bucket_size)
|
||||
}
|
||||
if let Some(bucket_leak_interval_in_secs) = new.bucket_leak_interval_in_secs {
|
||||
self.bucket_leak_interval_in_secs = Some(bucket_leak_interval_in_secs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EliminationRoutingConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
params: Some(vec![DynamicRoutingConfigParams::PaymentMethod]),
|
||||
elimination_analyser_config: Some(EliminationAnalyserConfig {
|
||||
bucket_size: Some(5),
|
||||
bucket_leak_interval_in_secs: Some(2),
|
||||
bucket_leak_interval_in_secs: Some(60),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EliminationRoutingConfig {
|
||||
pub fn update(&mut self, new: Self) {
|
||||
if let Some(params) = new.params {
|
||||
self.params = Some(params)
|
||||
}
|
||||
if let Some(new_config) = new.elimination_analyser_config {
|
||||
self.elimination_analyser_config
|
||||
.as_mut()
|
||||
.map(|config| config.update(new_config));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, ToSchema)]
|
||||
pub struct SuccessBasedRoutingConfig {
|
||||
pub params: Option<Vec<DynamicRoutingConfigParams>>,
|
||||
@ -917,6 +941,13 @@ pub struct SuccessBasedRoutingPayloadWrapper {
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct EliminationRoutingPayloadWrapper {
|
||||
pub updated_config: EliminationRoutingConfig,
|
||||
pub algorithm_id: common_utils::id_type::RoutingId,
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct ContractBasedRoutingPayloadWrapper {
|
||||
pub updated_config: ContractBasedRoutingConfig,
|
||||
|
||||
Reference in New Issue
Block a user