mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat: spawn webhooks and async scheduling in background (#2780)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: akshay-97 <adiosphobian@gmail.com> Co-authored-by: akshay.s <akshay.s@juspay.in> Co-authored-by: Kartikeya Hegde <karthikey.hegde@juspay.in>
This commit is contained in:
		| @ -493,7 +493,27 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve> Domain<F, api::PaymentsRequest | |||||||
|         requeue: bool, |         requeue: bool, | ||||||
|         schedule_time: Option<time::PrimitiveDateTime>, |         schedule_time: Option<time::PrimitiveDateTime>, | ||||||
|     ) -> CustomResult<(), errors::ApiErrorResponse> { |     ) -> CustomResult<(), errors::ApiErrorResponse> { | ||||||
|         helpers::add_domain_task_to_pt(self, state, payment_attempt, requeue, schedule_time).await |         // This spawns this futures in a background thread, the exception inside this future won't affect | ||||||
|  |         // the current thread and the lifecycle of spawn thread is not handled by runtime. | ||||||
|  |         // So when server shutdown won't wait for this thread's completion. | ||||||
|  |         let m_payment_attempt = payment_attempt.clone(); | ||||||
|  |         let m_state = state.clone(); | ||||||
|  |         let m_self = *self; | ||||||
|  |         tokio::spawn( | ||||||
|  |             async move { | ||||||
|  |                 helpers::add_domain_task_to_pt( | ||||||
|  |                     &m_self, | ||||||
|  |                     m_state.as_ref(), | ||||||
|  |                     &m_payment_attempt, | ||||||
|  |                     requeue, | ||||||
|  |                     schedule_time, | ||||||
|  |                 ) | ||||||
|  |                 .await | ||||||
|  |             } | ||||||
|  |             .in_current_span(), | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |         Ok(()) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async fn get_connector<'a>( |     async fn get_connector<'a>( | ||||||
|  | |||||||
| @ -24,6 +24,7 @@ use nanoid::nanoid; | |||||||
| use qrcode; | use qrcode; | ||||||
| use serde::de::DeserializeOwned; | use serde::de::DeserializeOwned; | ||||||
| use serde_json::Value; | use serde_json::Value; | ||||||
|  | use tracing_futures::Instrument; | ||||||
| use uuid::Uuid; | use uuid::Uuid; | ||||||
|  |  | ||||||
| pub use self::ext_traits::{OptionExt, ValidateCall}; | pub use self::ext_traits::{OptionExt, ValidateCall}; | ||||||
| @ -754,21 +755,30 @@ where | |||||||
|             payments_response |             payments_response | ||||||
|         { |         { | ||||||
|             let m_state = state.clone(); |             let m_state = state.clone(); | ||||||
|  |             // This spawns this futures in a background thread, the exception inside this future won't affect | ||||||
|             Box::pin( |             // the current thread and the lifecycle of spawn thread is not handled by runtime. | ||||||
|                 webhooks_core::create_event_and_trigger_appropriate_outgoing_webhook( |             // So when server shutdown won't wait for this thread's completion. | ||||||
|                     m_state, |             tokio::spawn( | ||||||
|                     merchant_account, |                 async move { | ||||||
|                     business_profile, |                     Box::pin( | ||||||
|                     event_type, |                         webhooks_core::create_event_and_trigger_appropriate_outgoing_webhook( | ||||||
|                     diesel_models::enums::EventClass::Payments, |                             m_state, | ||||||
|                     None, |                             merchant_account, | ||||||
|                     payment_id, |                             business_profile, | ||||||
|                     diesel_models::enums::EventObjectType::PaymentDetails, |                             event_type, | ||||||
|                     webhooks::OutgoingWebhookContent::PaymentDetails(payments_response_json), |                             diesel_models::enums::EventClass::Payments, | ||||||
|                 ), |                             None, | ||||||
|             ) |                             payment_id, | ||||||
|             .await?; |                             diesel_models::enums::EventObjectType::PaymentDetails, | ||||||
|  |                             webhooks::OutgoingWebhookContent::PaymentDetails( | ||||||
|  |                                 payments_response_json, | ||||||
|  |                             ), | ||||||
|  |                         ), | ||||||
|  |                     ) | ||||||
|  |                     .await | ||||||
|  |                 } | ||||||
|  |                 .in_current_span(), | ||||||
|  |             ); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Arun Raj M
					Arun Raj M