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:
Arun Raj M
2023-11-16 15:42:10 +05:30
committed by GitHub
parent bd55e57a5b
commit f248fe2889
2 changed files with 46 additions and 16 deletions

View File

@ -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,21 +755,30 @@ where
payments_response
{
let m_state = state.clone();
Box::pin(
webhooks_core::create_event_and_trigger_appropriate_outgoing_webhook(
m_state,
merchant_account,
business_profile,
event_type,
diesel_models::enums::EventClass::Payments,
None,
payment_id,
diesel_models::enums::EventObjectType::PaymentDetails,
webhooks::OutgoingWebhookContent::PaymentDetails(payments_response_json),
),
)
.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.
tokio::spawn(
async move {
Box::pin(
webhooks_core::create_event_and_trigger_appropriate_outgoing_webhook(
m_state,
merchant_account,
business_profile,
event_type,
diesel_models::enums::EventClass::Payments,
None,
payment_id,
diesel_models::enums::EventObjectType::PaymentDetails,
webhooks::OutgoingWebhookContent::PaymentDetails(
payments_response_json,
),
),
)
.await
}
.in_current_span(),
);
}
}