mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
feat(routing): add invalidate window as a service for SR based routing (#6264)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -14,8 +14,9 @@ use serde;
|
||||
use success_rate::{
|
||||
success_rate_calculator_client::SuccessRateCalculatorClient, CalSuccessRateConfig,
|
||||
CalSuccessRateRequest, CalSuccessRateResponse,
|
||||
CurrentBlockThreshold as DynamicCurrentThreshold, LabelWithStatus,
|
||||
UpdateSuccessRateWindowConfig, UpdateSuccessRateWindowRequest, UpdateSuccessRateWindowResponse,
|
||||
CurrentBlockThreshold as DynamicCurrentThreshold, InvalidateWindowsRequest,
|
||||
InvalidateWindowsResponse, LabelWithStatus, UpdateSuccessRateWindowConfig,
|
||||
UpdateSuccessRateWindowRequest, UpdateSuccessRateWindowResponse,
|
||||
};
|
||||
use tonic::Status;
|
||||
#[allow(
|
||||
@ -111,6 +112,11 @@ pub trait SuccessBasedDynamicRouting: dyn_clone::DynClone + Send + Sync {
|
||||
params: String,
|
||||
response: Vec<RoutableConnectorChoiceWithStatus>,
|
||||
) -> DynamicRoutingResult<UpdateSuccessRateWindowResponse>;
|
||||
/// To invalidates the success rate routing keys
|
||||
async fn invalidate_success_rate_routing_keys(
|
||||
&self,
|
||||
id: String,
|
||||
) -> DynamicRoutingResult<InvalidateWindowsResponse>;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@ -139,9 +145,8 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
config,
|
||||
});
|
||||
|
||||
let mut client = self.clone();
|
||||
|
||||
let response = client
|
||||
let response = self
|
||||
.clone()
|
||||
.fetch_success_rate(request)
|
||||
.await
|
||||
.change_context(DynamicRoutingError::SuccessRateBasedRoutingFailure(
|
||||
@ -179,9 +184,8 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
config,
|
||||
});
|
||||
|
||||
let mut client = self.clone();
|
||||
|
||||
let response = client
|
||||
let response = self
|
||||
.clone()
|
||||
.update_success_rate_window(request)
|
||||
.await
|
||||
.change_context(DynamicRoutingError::SuccessRateBasedRoutingFailure(
|
||||
@ -191,6 +195,23 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
async fn invalidate_success_rate_routing_keys(
|
||||
&self,
|
||||
id: String,
|
||||
) -> DynamicRoutingResult<InvalidateWindowsResponse> {
|
||||
let request = tonic::Request::new(InvalidateWindowsRequest { id });
|
||||
|
||||
let response = self
|
||||
.clone()
|
||||
.invalidate_windows(request)
|
||||
.await
|
||||
.change_context(DynamicRoutingError::SuccessRateBasedRoutingFailure(
|
||||
"Failed to invalidate the success rate routing keys".to_string(),
|
||||
))?
|
||||
.into_inner();
|
||||
Ok(response)
|
||||
}
|
||||
}
|
||||
|
||||
impl ForeignTryFrom<CurrentBlockThreshold> for DynamicCurrentThreshold {
|
||||
|
||||
Reference in New Issue
Block a user