mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
feat(connector): Add support for passive churn recovery webhooks (#7109)
Co-authored-by: Chikke Srujan <chikke.srujan@Chikke-Srujan-N7WRTY72X7.local> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
use error_stack::ResultExt;
|
||||
use masking::{ExposeInterface, PeekInterface, Secret, Strategy};
|
||||
use quick_xml::de;
|
||||
#[cfg(all(feature = "logs", feature = "async_ext"))]
|
||||
use router_env::logger;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
@ -295,28 +297,34 @@ impl<T> StringExt<T> for String {
|
||||
/// Extending functionalities of Wrapper types for idiomatic
|
||||
#[cfg(feature = "async_ext")]
|
||||
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
|
||||
pub trait AsyncExt<A, B> {
|
||||
pub trait AsyncExt<A> {
|
||||
/// Output type of the map function
|
||||
type WrappedSelf<T>;
|
||||
|
||||
/// Extending map by allowing functions which are async
|
||||
async fn async_map<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
async fn async_map<F, B, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
where
|
||||
F: FnOnce(A) -> Fut + Send,
|
||||
Fut: futures::Future<Output = B> + Send;
|
||||
|
||||
/// Extending the `and_then` by allowing functions which are async
|
||||
async fn async_and_then<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
async fn async_and_then<F, B, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
where
|
||||
F: FnOnce(A) -> Fut + Send,
|
||||
Fut: futures::Future<Output = Self::WrappedSelf<B>> + Send;
|
||||
|
||||
/// Extending `unwrap_or_else` to allow async fallback
|
||||
async fn async_unwrap_or_else<F, Fut>(self, func: F) -> A
|
||||
where
|
||||
F: FnOnce() -> Fut + Send,
|
||||
Fut: futures::Future<Output = A> + Send;
|
||||
}
|
||||
|
||||
#[cfg(feature = "async_ext")]
|
||||
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
|
||||
impl<A: Send, B, E: Send> AsyncExt<A, B> for Result<A, E> {
|
||||
impl<A: Send, E: Send + std::fmt::Debug> AsyncExt<A> for Result<A, E> {
|
||||
type WrappedSelf<T> = Result<T, E>;
|
||||
async fn async_and_then<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
async fn async_and_then<F, B, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
where
|
||||
F: FnOnce(A) -> Fut + Send,
|
||||
Fut: futures::Future<Output = Self::WrappedSelf<B>> + Send,
|
||||
@ -327,7 +335,7 @@ impl<A: Send, B, E: Send> AsyncExt<A, B> for Result<A, E> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn async_map<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
async fn async_map<F, B, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
where
|
||||
F: FnOnce(A) -> Fut + Send,
|
||||
Fut: futures::Future<Output = B> + Send,
|
||||
@ -337,13 +345,28 @@ impl<A: Send, B, E: Send> AsyncExt<A, B> for Result<A, E> {
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
async fn async_unwrap_or_else<F, Fut>(self, func: F) -> A
|
||||
where
|
||||
F: FnOnce() -> Fut + Send,
|
||||
Fut: futures::Future<Output = A> + Send,
|
||||
{
|
||||
match self {
|
||||
Ok(a) => a,
|
||||
Err(_err) => {
|
||||
#[cfg(feature = "logs")]
|
||||
logger::error!("Error: {:?}", _err);
|
||||
func().await
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async_ext")]
|
||||
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
|
||||
impl<A: Send, B> AsyncExt<A, B> for Option<A> {
|
||||
impl<A: Send> AsyncExt<A> for Option<A> {
|
||||
type WrappedSelf<T> = Option<T>;
|
||||
async fn async_and_then<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
async fn async_and_then<F, B, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
where
|
||||
F: FnOnce(A) -> Fut + Send,
|
||||
Fut: futures::Future<Output = Self::WrappedSelf<B>> + Send,
|
||||
@ -354,7 +377,7 @@ impl<A: Send, B> AsyncExt<A, B> for Option<A> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn async_map<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
async fn async_map<F, B, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
where
|
||||
F: FnOnce(A) -> Fut + Send,
|
||||
Fut: futures::Future<Output = B> + Send,
|
||||
@ -364,6 +387,17 @@ impl<A: Send, B> AsyncExt<A, B> for Option<A> {
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
async fn async_unwrap_or_else<F, Fut>(self, func: F) -> A
|
||||
where
|
||||
F: FnOnce() -> Fut + Send,
|
||||
Fut: futures::Future<Output = A> + Send,
|
||||
{
|
||||
match self {
|
||||
Some(a) => a,
|
||||
None => func().await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait for validating application configuration. This trait provides utilities to
|
||||
|
||||
Reference in New Issue
Block a user