mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
feat(routing): Enable volume split for dynamic routing (#6662)
Co-authored-by: prajjwalkumar17 <write2prajjwal@gmail.com> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: prajjwalkumar17 <prajjwal.kumar@juspay.in>
This commit is contained in:
@ -4,9 +4,9 @@ use crate::routing::{
|
||||
LinkedRoutingConfigRetrieveResponse, MerchantRoutingAlgorithm, ProfileDefaultRoutingConfig,
|
||||
RoutingAlgorithmId, RoutingConfigRequest, RoutingDictionaryRecord, RoutingKind,
|
||||
RoutingLinkWrapper, RoutingPayloadWrapper, RoutingRetrieveLinkQuery,
|
||||
RoutingRetrieveLinkQueryWrapper, RoutingRetrieveQuery, SuccessBasedRoutingConfig,
|
||||
SuccessBasedRoutingPayloadWrapper, SuccessBasedRoutingUpdateConfigQuery,
|
||||
ToggleDynamicRoutingQuery, ToggleDynamicRoutingWrapper,
|
||||
RoutingRetrieveLinkQueryWrapper, RoutingRetrieveQuery, RoutingVolumeSplitWrapper,
|
||||
SuccessBasedRoutingConfig, SuccessBasedRoutingPayloadWrapper,
|
||||
SuccessBasedRoutingUpdateConfigQuery, ToggleDynamicRoutingQuery, ToggleDynamicRoutingWrapper,
|
||||
};
|
||||
|
||||
impl ApiEventMetric for RoutingKind {
|
||||
@ -108,3 +108,9 @@ impl ApiEventMetric for SuccessBasedRoutingUpdateConfigQuery {
|
||||
Some(ApiEventsType::Routing)
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiEventMetric for RoutingVolumeSplitWrapper {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Routing)
|
||||
}
|
||||
}
|
||||
|
||||
@ -522,6 +522,7 @@ pub struct DynamicAlgorithmWithTimestamp<T> {
|
||||
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct DynamicRoutingAlgorithmRef {
|
||||
pub success_based_algorithm: Option<SuccessBasedAlgorithm>,
|
||||
pub dynamic_routing_volume_split: Option<u8>,
|
||||
pub elimination_routing_algorithm: Option<EliminationRoutingAlgorithm>,
|
||||
}
|
||||
|
||||
@ -554,32 +555,6 @@ impl DynamicRoutingAlgoAccessor for EliminationRoutingAlgorithm {
|
||||
}
|
||||
}
|
||||
|
||||
impl EliminationRoutingAlgorithm {
|
||||
pub fn new(
|
||||
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp<
|
||||
common_utils::id_type::RoutingId,
|
||||
>,
|
||||
) -> Self {
|
||||
Self {
|
||||
algorithm_id_with_timestamp,
|
||||
enabled_feature: DynamicRoutingFeatures::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SuccessBasedAlgorithm {
|
||||
pub fn new(
|
||||
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp<
|
||||
common_utils::id_type::RoutingId,
|
||||
>,
|
||||
) -> Self {
|
||||
Self {
|
||||
algorithm_id_with_timestamp,
|
||||
enabled_feature: DynamicRoutingFeatures::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DynamicRoutingAlgorithmRef {
|
||||
pub fn update(&mut self, new: Self) {
|
||||
if let Some(elimination_routing_algorithm) = new.elimination_routing_algorithm {
|
||||
@ -608,8 +583,63 @@ impl DynamicRoutingAlgorithmRef {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_volume_split(&mut self, volume: Option<u8>) {
|
||||
self.dynamic_routing_volume_split = volume
|
||||
}
|
||||
}
|
||||
|
||||
impl EliminationRoutingAlgorithm {
|
||||
pub fn new(
|
||||
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp<
|
||||
common_utils::id_type::RoutingId,
|
||||
>,
|
||||
) -> Self {
|
||||
Self {
|
||||
algorithm_id_with_timestamp,
|
||||
enabled_feature: DynamicRoutingFeatures::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SuccessBasedAlgorithm {
|
||||
pub fn new(
|
||||
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp<
|
||||
common_utils::id_type::RoutingId,
|
||||
>,
|
||||
) -> Self {
|
||||
Self {
|
||||
algorithm_id_with_timestamp,
|
||||
enabled_feature: DynamicRoutingFeatures::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, serde::Serialize, serde::Deserialize)]
|
||||
pub struct RoutingVolumeSplit {
|
||||
pub routing_type: RoutingType,
|
||||
pub split: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct RoutingVolumeSplitWrapper {
|
||||
pub routing_info: RoutingVolumeSplit,
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RoutingType {
|
||||
#[default]
|
||||
Static,
|
||||
Dynamic,
|
||||
}
|
||||
|
||||
impl RoutingType {
|
||||
pub fn is_dynamic_routing(self) -> bool {
|
||||
self == Self::Dynamic
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct SuccessBasedAlgorithm {
|
||||
pub algorithm_id_with_timestamp:
|
||||
@ -673,6 +703,11 @@ pub struct ToggleDynamicRoutingQuery {
|
||||
pub enable: DynamicRoutingFeatures,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct DynamicRoutingVolumeSplitQuery {
|
||||
pub split: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DynamicRoutingFeatures {
|
||||
|
||||
Reference in New Issue
Block a user