mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 01:57:45 +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, | ||||
|         schedule_time: Option<time::PrimitiveDateTime>, | ||||
|     ) -> 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>( | ||||
|  | ||||
| @ -24,6 +24,7 @@ use nanoid::nanoid; | ||||
| use qrcode; | ||||
| use serde::de::DeserializeOwned; | ||||
| use serde_json::Value; | ||||
| use tracing_futures::Instrument; | ||||
| use uuid::Uuid; | ||||
|  | ||||
| pub use self::ext_traits::{OptionExt, ValidateCall}; | ||||
| @ -754,7 +755,11 @@ where | ||||
|             payments_response | ||||
|         { | ||||
|             let m_state = state.clone(); | ||||
|  | ||||
|             // 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. | ||||
|             tokio::spawn( | ||||
|                 async move { | ||||
|                     Box::pin( | ||||
|                         webhooks_core::create_event_and_trigger_appropriate_outgoing_webhook( | ||||
|                             m_state, | ||||
| @ -765,10 +770,15 @@ where | ||||
|                             None, | ||||
|                             payment_id, | ||||
|                             diesel_models::enums::EventObjectType::PaymentDetails, | ||||
|                     webhooks::OutgoingWebhookContent::PaymentDetails(payments_response_json), | ||||
|                             webhooks::OutgoingWebhookContent::PaymentDetails( | ||||
|                                 payments_response_json, | ||||
|                             ), | ||||
|                         ), | ||||
|                     ) | ||||
|             .await?; | ||||
|                     .await | ||||
|                 } | ||||
|                 .in_current_span(), | ||||
|             ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Arun Raj M
					Arun Raj M