From 75765bc14bca8bae01a70b2fc511e04d147188f3 Mon Sep 17 00:00:00 2001 From: Amitsingh Tanwar Date: Sun, 28 Sep 2025 19:22:51 +0530 Subject: [PATCH] chore: added tokio::spawn to make things parallel --- crates/router/src/core/payments.rs | 49 +++++++++++++----------- crates/router/src/core/payments/retry.rs | 22 +++++------ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 6efa29c77c..e1140d806d 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -528,7 +528,7 @@ where #[cfg(feature = "v1")] #[allow(clippy::too_many_arguments, clippy::type_complexity)] #[instrument(skip_all, fields(payment_id, merchant_id))] -pub async fn payments_operation_core( +pub async fn payments_operation_core<'a, F, Req, Op, FData, D>( state: &SessionState, req_state: ReqState, merchant_context: &domain::MerchantContext, @@ -541,7 +541,7 @@ pub async fn payments_operation_core( header_payload: HeaderPayload, ) -> RouterResult<(D, Req, Option, Option, Option)> where - F: Send + Clone + Sync, + F: Send + Clone + Sync + 'static + 'a, Req: Authenticate + Clone, Op: Operation + Send + Sync, D: OperationSessionGetters + OperationSessionSetters + Send + Sync + Clone, @@ -556,7 +556,7 @@ where // To perform router related operation for PaymentResponse PaymentResponse: Operation, - FData: Send + Sync + Clone + router_types::Capturable, + FData: Send + Sync + Clone + router_types::Capturable + 'static + 'a, { let operation: BoxedOperation<'_, F, Req, D> = Box::new(operation); @@ -2081,7 +2081,7 @@ pub async fn call_surcharge_decision_management_for_session_flow( #[cfg(feature = "v1")] #[allow(clippy::too_many_arguments)] -pub async fn payments_core( +pub async fn payments_core<'a, F, Res, Req, Op, FData, D>( state: SessionState, req_state: ReqState, merchant_context: domain::MerchantContext, @@ -2094,8 +2094,8 @@ pub async fn payments_core( header_payload: HeaderPayload, ) -> RouterResponse where - F: Send + Clone + Sync, - FData: Send + Sync + Clone + router_types::Capturable, + F: Send + Clone + Sync + 'static + 'a, + FData: Send + Sync + Clone + router_types::Capturable + 'static + 'a, Op: Operation + Send + Sync + Clone, Req: Debug + Authenticate + Clone, D: OperationSessionGetters + OperationSessionSetters + Send + Sync + Clone, @@ -4213,20 +4213,20 @@ where #[cfg(feature = "v1")] #[allow(clippy::too_many_arguments)] #[instrument(skip_all)] -pub async fn decide_unified_connector_service_call( - state: &SessionState, +pub async fn decide_unified_connector_service_call<'a, F, RouterDReq, ApiRequest, D>( + state: &'a SessionState, req_state: ReqState, - merchant_context: &domain::MerchantContext, + merchant_context: &'a domain::MerchantContext, connector: api::ConnectorData, - operation: &BoxedOperation<'_, F, ApiRequest, D>, - payment_data: &mut D, + operation: &'a BoxedOperation<'a, F, ApiRequest, D>, + payment_data: &'a mut D, customer: &Option, call_connector_action: CallConnectorAction, - validate_result: &operations::ValidateResult, + validate_result: &'a operations::ValidateResult, schedule_time: Option, header_payload: HeaderPayload, frm_suggestion: Option, - business_profile: &domain::Profile, + business_profile: &'a domain::Profile, is_retry_payment: bool, all_keys_required: Option, merchant_connector_account: helpers::MerchantConnectorAccountType, @@ -4237,8 +4237,8 @@ pub async fn decide_unified_connector_service_call helpers::MerchantConnectorAccountType, )> where - F: Send + Clone + Sync, - RouterDReq: Send + Sync + Clone, + F: Send + Clone + Sync + 'static + 'a, + RouterDReq: Send + Sync + Clone + 'static + 'a, // To create connector flow specific interface data D: OperationSessionGetters + OperationSessionSetters + Send + Sync + Clone, @@ -4326,16 +4326,21 @@ where .get_string_repr(), payment_data.get_payment_attempt().attempt_id ); + let ucs_merchant_connector_account = merchant_connector_account.clone(); + let ucs_merchant_context = merchant_context.clone(); // Update feature metadata to track Direct routing usage for stickiness update_gateway_system_in_feature_metadata(payment_data, GatewaySystem::Direct)?; - let _result = rd - .call_unified_connector_service( - state, - merchant_connector_account.clone(), - merchant_context, - ) - .await?; + let ucs_state = state.clone(); + tokio::spawn(async move { + let _result = rd + .call_unified_connector_service( + &ucs_state, + ucs_merchant_connector_account, + &ucs_merchant_context, + ) + .await; + }); call_connector_service( state, diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index c4b72277a9..f21eea3484 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -32,7 +32,7 @@ use crate::{ #[instrument(skip_all)] #[allow(clippy::too_many_arguments)] #[cfg(feature = "v1")] -pub async fn do_gsm_actions( +pub async fn do_gsm_actions<'a, F, ApiRequest, FData, D>( state: &app::SessionState, req_state: ReqState, payment_data: &mut D, @@ -48,8 +48,8 @@ pub async fn do_gsm_actions( business_profile: &domain::Profile, ) -> RouterResult> where - F: Clone + Send + Sync, - FData: Send + Sync + types::Capturable + Clone, + F: Clone + Send + Sync + 'static + 'a, + FData: Send + Sync + types::Capturable + Clone + 'static + 'a, payments::PaymentResponse: operations::Operation, D: payments::OperationSessionGetters + payments::OperationSessionSetters @@ -338,14 +338,14 @@ fn get_flow_name() -> RouterResult { #[cfg(feature = "v1")] #[allow(clippy::too_many_arguments)] #[instrument(skip_all)] -pub async fn do_retry( - state: &routes::SessionState, +pub async fn do_retry<'a, F, ApiRequest, FData, D>( + state: &'a routes::SessionState, req_state: ReqState, - connector: &api::ConnectorData, - operation: &operations::BoxedOperation<'_, F, ApiRequest, D>, - customer: &Option, + connector: &'a api::ConnectorData, + operation: &'a operations::BoxedOperation<'a, F, ApiRequest, D>, + customer: &'a Option, merchant_context: &domain::MerchantContext, - payment_data: &mut D, + payment_data: &'a mut D, router_data: types::RouterData, validate_result: &operations::ValidateResult, schedule_time: Option, @@ -356,8 +356,8 @@ pub async fn do_retry( routing_decision: Option, ) -> RouterResult> where - F: Clone + Send + Sync, - FData: Send + Sync + types::Capturable + Clone, + F: Clone + Send + Sync + 'static + 'a, + FData: Send + Sync + types::Capturable + Clone + 'static + 'a, payments::PaymentResponse: operations::Operation, D: payments::OperationSessionGetters + payments::OperationSessionSetters