From 0695d7daf83e5bd91640df7f92ee48d58195d494 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 23 May 2024 10:41:12 +0000 Subject: [PATCH] chore: run formatter --- crates/diesel_models/src/customers.rs | 10 ++--- crates/diesel_models/src/mandate.rs | 25 ++++++----- crates/diesel_models/src/payment_method.rs | 33 ++++++++------- crates/router/src/configs/defaults.rs | 5 ++- crates/router/src/configs/settings.rs | 7 ++-- crates/router/src/core/admin.rs | 5 ++- crates/router/src/core/customers.rs | 2 +- .../router/src/core/payment_methods/cards.rs | 2 +- crates/router/src/core/payments/helpers.rs | 2 +- crates/router/src/core/payouts/helpers.rs | 2 +- crates/router/src/db/address.rs | 22 ++++++++-- crates/router/src/db/customers.rs | 26 +++++++++--- crates/router/src/db/mandate.rs | 28 ++++++++++--- crates/router/src/db/payment_method.rs | 42 +++++++++++++++---- crates/router/src/db/refund.rs | 35 ++++++++++++---- crates/router/src/db/reverse_lookup.rs | 10 +++-- crates/router/src/types/domain/customer.rs | 8 ++-- crates/storage_impl/src/lib.rs | 9 ++-- crates/storage_impl/src/lookup.rs | 8 ++-- .../src/payments/payment_attempt.rs | 37 +++++++++++----- .../src/payments/payment_intent.rs | 17 +++++--- .../src/payouts/payout_attempt.rs | 15 +++++-- crates/storage_impl/src/payouts/payouts.rs | 18 +++++--- crates/storage_impl/src/redis/kv_store.rs | 33 ++++++++------- 24 files changed, 275 insertions(+), 126 deletions(-) diff --git a/crates/diesel_models/src/customers.rs b/crates/diesel_models/src/customers.rs index e2f67d86803a..0d1657136e02 100644 --- a/crates/diesel_models/src/customers.rs +++ b/crates/diesel_models/src/customers.rs @@ -22,11 +22,11 @@ pub struct CustomerNew { pub created_at: PrimitiveDateTime, pub modified_at: PrimitiveDateTime, pub address_id: Option, - pub updated_by : Option, + pub updated_by: Option, } -impl CustomerNew{ - pub fn update_storage_scheme(&mut self, storage_scheme: MerchantStorageScheme){ +impl CustomerNew { + pub fn update_storage_scheme(&mut self, storage_scheme: MerchantStorageScheme) { self.updated_by = Some(storage_scheme.to_string()); } } @@ -48,7 +48,7 @@ impl From for Customer { modified_at: customer_new.modified_at, address_id: customer_new.address_id, default_payment_method_id: None, - updated_by : customer_new.updated_by + updated_by: customer_new.updated_by, } } } @@ -70,7 +70,7 @@ pub struct Customer { pub modified_at: PrimitiveDateTime, pub address_id: Option, pub default_payment_method_id: Option, - pub updated_by : Option, + pub updated_by: Option, } #[derive( diff --git a/crates/diesel_models/src/mandate.rs b/crates/diesel_models/src/mandate.rs index 61b0885bea07..65576b08f237 100644 --- a/crates/diesel_models/src/mandate.rs +++ b/crates/diesel_models/src/mandate.rs @@ -71,11 +71,11 @@ pub struct MandateNew { pub connector_mandate_ids: Option, pub original_payment_id: Option, pub merchant_connector_id: Option, - pub updated_by : Option + pub updated_by: Option, } -impl MandateNew{ - pub fn update_storage_scheme(&mut self, storage_scheme: MerchantStorageScheme){ +impl MandateNew { + pub fn update_storage_scheme(&mut self, storage_scheme: MerchantStorageScheme) { self.updated_by = Some(storage_scheme.to_string()); } } @@ -99,8 +99,11 @@ pub enum MandateUpdate { }, } -impl MandateUpdate{ - pub fn convert_to_mandate_update(self, storage_scheme: MerchantStorageScheme) -> MandateUpdateInternal{ +impl MandateUpdate { + pub fn convert_to_mandate_update( + self, + storage_scheme: MerchantStorageScheme, + ) -> MandateUpdateInternal { let mut updated_object = MandateUpdateInternal::from(self); updated_object.updated_by = Some(storage_scheme.to_string()); updated_object @@ -130,7 +133,7 @@ pub struct MandateUpdateInternal { connector_mandate_id: Option, payment_method_id: Option, original_payment_id: Option, - updated_by : Option + updated_by: Option, } impl From for MandateUpdateInternal { @@ -143,7 +146,7 @@ impl From for MandateUpdateInternal { connector_mandate_id: None, payment_method_id: None, original_payment_id: None, - updated_by : None + updated_by: None, }, MandateUpdate::CaptureAmountUpdate { amount_captured } => Self { mandate_status: None, @@ -152,7 +155,7 @@ impl From for MandateUpdateInternal { connector_mandate_id: None, payment_method_id: None, original_payment_id: None, - updated_by : None + updated_by: None, }, MandateUpdate::ConnectorReferenceUpdate { connector_mandate_ids, @@ -185,7 +188,7 @@ impl MandateUpdateInternal { connector_mandate_id, payment_method_id, original_payment_id, - updated_by + updated_by, } = self; Mandate { @@ -195,7 +198,7 @@ impl MandateUpdateInternal { connector_mandate_id: connector_mandate_id.map_or(source.connector_mandate_id, Some), payment_method_id: payment_method_id.unwrap_or(source.payment_method_id), original_payment_id: original_payment_id.map_or(source.original_payment_id, Some), - updated_by : updated_by.map_or(source.updated_by, Some), + updated_by: updated_by.map_or(source.updated_by, Some), ..source } } @@ -230,7 +233,7 @@ impl From<&MandateNew> for Mandate { connector_mandate_ids: mandate_new.connector_mandate_ids.clone(), original_payment_id: mandate_new.original_payment_id.clone(), merchant_connector_id: mandate_new.merchant_connector_id.clone(), - updated_by : mandate_new.updated_by.clone(), + updated_by: mandate_new.updated_by.clone(), } } } diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs index 62d0b281de0f..99e0972e3daa 100644 --- a/crates/diesel_models/src/payment_method.rs +++ b/crates/diesel_models/src/payment_method.rs @@ -42,7 +42,7 @@ pub struct PaymentMethod { pub network_transaction_id: Option, pub client_secret: Option, pub payment_method_billing_address: Option, - pub updated_by : Option, + pub updated_by: Option, } #[derive( @@ -79,11 +79,11 @@ pub struct PaymentMethodNew { pub network_transaction_id: Option, pub client_secret: Option, pub payment_method_billing_address: Option, - pub updated_by : Option, + pub updated_by: Option, } impl PaymentMethodNew { - pub fn update_storage_scheme(&mut self, storage_scheme : MerchantStorageScheme){ + pub fn update_storage_scheme(&mut self, storage_scheme: MerchantStorageScheme) { self.updated_by = Some(storage_scheme.to_string()); } } @@ -125,9 +125,12 @@ pub enum PaymentMethodUpdate { }, } -impl PaymentMethodUpdate{ - pub fn convert_to_payment_method_update(self, storage_scheme : MerchantStorageScheme) -> PaymentMethodUpdateInternal{ - let mut update_internal : PaymentMethodUpdateInternal = self.into(); +impl PaymentMethodUpdate { + pub fn convert_to_payment_method_update( + self, + storage_scheme: MerchantStorageScheme, + ) -> PaymentMethodUpdateInternal { + let mut update_internal: PaymentMethodUpdateInternal = self.into(); update_internal.updated_by = Some(storage_scheme.to_string()); update_internal } @@ -148,7 +151,7 @@ pub struct PaymentMethodUpdateInternal { connector_mandate_details: Option, payment_method_type: Option, payment_method_issuer: Option, - updated_by : Option + updated_by: Option, } impl PaymentMethodUpdateInternal { @@ -179,7 +182,7 @@ impl PaymentMethodUpdateInternal { status: status.unwrap_or(source.status), connector_mandate_details: connector_mandate_details .map_or(source.connector_mandate_details, Some), - updated_by : updated_by.map_or(source.updated_by, Some), + updated_by: updated_by.map_or(source.updated_by, Some), ..source } } @@ -199,7 +202,7 @@ impl From for PaymentMethodUpdateInternal { connector_mandate_details: None, payment_method_issuer: None, payment_method_type: None, - updated_by : None, + updated_by: None, }, PaymentMethodUpdate::PaymentMethodDataUpdate { payment_method_data, @@ -227,7 +230,7 @@ impl From for PaymentMethodUpdateInternal { connector_mandate_details: None, payment_method_issuer: None, payment_method_type: None, - updated_by : None, + updated_by: None, }, PaymentMethodUpdate::NetworkTransactionIdAndStatusUpdate { network_transaction_id, @@ -243,7 +246,7 @@ impl From for PaymentMethodUpdateInternal { connector_mandate_details: None, payment_method_issuer: None, payment_method_type: None, - updated_by : None, + updated_by: None, }, PaymentMethodUpdate::StatusUpdate { status } => Self { metadata: None, @@ -256,7 +259,7 @@ impl From for PaymentMethodUpdateInternal { connector_mandate_details: None, payment_method_issuer: None, payment_method_type: None, - updated_by : None, + updated_by: None, }, PaymentMethodUpdate::AdditionalDataUpdate { payment_method_data, @@ -276,7 +279,7 @@ impl From for PaymentMethodUpdateInternal { connector_mandate_details: None, payment_method_issuer, payment_method_type, - updated_by : None, + updated_by: None, }, PaymentMethodUpdate::ConnectorMandateDetailsUpdate { connector_mandate_details, @@ -291,7 +294,7 @@ impl From for PaymentMethodUpdateInternal { network_transaction_id: None, payment_method_issuer: None, payment_method_type: None, - updated_by : None, + updated_by: None, }, } } @@ -332,7 +335,7 @@ impl From<&PaymentMethodNew> for PaymentMethod { payment_method_billing_address: payment_method_new .payment_method_billing_address .clone(), - updated_by : payment_method_new.updated_by.clone(), + updated_by: payment_method_new.updated_by.clone(), } } } diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs index 6c6dd2219196..213492ac0d93 100644 --- a/crates/router/src/configs/defaults.rs +++ b/crates/router/src/configs/defaults.rs @@ -123,7 +123,10 @@ impl Default for super::settings::DrainerSettings { #[cfg(feature = "kv_store")] impl Default for super::settings::KvConfig { fn default() -> Self { - Self { ttl: 900 , soft_kill : Some(false)} + Self { + ttl: 900, + soft_kill: Some(false), + } } } diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs index 3c6fe9048b01..9564a759ccd8 100644 --- a/crates/router/src/configs/settings.rs +++ b/crates/router/src/configs/settings.rs @@ -18,7 +18,7 @@ use external_services::{ }, }; use hyperswitch_interfaces::secrets_interface::secret_state::{ - SecretState, SecretStateContainer, SecuredSecret, RawSecret + RawSecret, SecretState, SecretStateContainer, SecuredSecret, }; use masking::Secret; use redis_interface::RedisSettings; @@ -761,16 +761,15 @@ impl Settings { } impl Settings { - #[cfg(feature ="kv_store")] + #[cfg(feature = "kv_store")] pub fn is_kv_soft_kill_mode(&self) -> bool { self.kv_config.soft_kill.unwrap_or(false) } - #[cfg(not(feature ="kv_store"))] + #[cfg(not(feature = "kv_store"))] pub fn is_kv_soft_kill_mode(&self) -> bool { false } - } #[cfg(feature = "payouts")] diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 56b894f0ee6e..0a70d3f058b5 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -1382,9 +1382,10 @@ pub async fn kv_for_merchant( Ok(merchant_account) } (true, MerchantStorageScheme::PostgresOnly) => { - if state.conf.as_ref().is_kv_soft_kill_mode(){ + if state.conf.as_ref().is_kv_soft_kill_mode() { Err(errors::ApiErrorResponse::InvalidRequestData { - message : "Kv cannot be enabled when application is in soft_kill_mode".to_owned() + message: "Kv cannot be enabled when application is in soft_kill_mode" + .to_owned(), })? } diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rs index f75ced79bbeb..0f3d60cccd79 100644 --- a/crates/router/src/core/customers.rs +++ b/crates/router/src/core/customers.rs @@ -116,7 +116,7 @@ pub async fn create_customer( created_at: common_utils::date_time::now(), modified_at: common_utils::date_time::now(), default_payment_method_id: None, - updated_by : None, + updated_by: None, }) } .await diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 8074ac638caa..7688fa33a362 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -140,7 +140,7 @@ pub async fn create_payment_method( last_modified: current_time, last_used_at: current_time, payment_method_billing_address, - updated_by : None, + updated_by: None, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 2c63e5097e1b..c1b48a361391 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1608,7 +1608,7 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R>( connector_customer: None, address_id: None, default_payment_method_id: None, - updated_by : None + updated_by: None, }, ) } diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rs index 0506d776e758..f356e5f05a14 100644 --- a/crates/router/src/core/payouts/helpers.rs +++ b/crates/router/src/core/payouts/helpers.rs @@ -626,7 +626,7 @@ pub async fn get_or_create_customer_details( modified_at: common_utils::date_time::now(), address_id: None, default_payment_method_id: None, - updated_by : None, + updated_by: None, }; Ok(Some( diff --git a/crates/router/src/db/address.rs b/crates/router/src/db/address.rs index fa392716a436..5a6b2606d0c1 100644 --- a/crates/router/src/db/address.rs +++ b/crates/router/src/db/address.rs @@ -275,7 +275,9 @@ mod storage { use error_stack::{report, ResultExt}; use redis_interface::HsetnxReply; use router_env::{instrument, tracing}; - use storage_impl::redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}; + use storage_impl::redis::kv_store::{ + decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey, + }; use super::AddressInterface; use crate::{ @@ -332,7 +334,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,storage_types::Address>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, storage_types::Address>(self, storage_scheme, Op::Find) + .await; let address = match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -401,7 +405,12 @@ mod storage { payment_id: &payment_id, }; let field = format!("add_{}", address.address_id); - let storage_scheme = decide_storage_scheme::<_,storage_types::Address>(self,storage_scheme, Op::Update(key.clone(), &field, Some(address.updated_by.as_str()))).await; + let storage_scheme = decide_storage_scheme::<_, storage_types::Address>( + self, + storage_scheme, + Op::Update(key.clone(), &field, Some(address.updated_by.as_str())), + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { address @@ -468,7 +477,12 @@ mod storage { .await .change_context(errors::StorageError::EncryptionError)?; let merchant_id = address_new.merchant_id.clone(); - let storage_scheme = decide_storage_scheme::<_,storage_types::Address>(self,storage_scheme, Op::Insert).await; + let storage_scheme = decide_storage_scheme::<_, storage_types::Address>( + self, + storage_scheme, + Op::Insert, + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { let conn = connection::pg_connection_write(self).await?; diff --git a/crates/router/src/db/customers.rs b/crates/router/src/db/customers.rs index 7ab328598d15..5f8dbe69f803 100644 --- a/crates/router/src/db/customers.rs +++ b/crates/router/src/db/customers.rs @@ -75,7 +75,9 @@ mod storage { use futures::future::try_join_all; use masking::PeekInterface; use router_env::{instrument, tracing}; - use storage_impl::redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}; + use storage_impl::redis::kv_store::{ + decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey, + }; use super::CustomerInterface; use crate::{ @@ -116,7 +118,9 @@ mod storage { .await .map_err(|err| report!(errors::StorageError::from(err))) }; - let storage_scheme = decide_storage_scheme::<_,diesel_models::Customer>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, diesel_models::Customer>(self, storage_scheme, Op::Find) + .await; let maybe_customer = match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -189,7 +193,12 @@ mod storage { customer_id: customer_id.as_str(), }; let field = format!("cust_{}", customer_id); - let storage_scheme = decide_storage_scheme::<_,diesel_models::Customer>(self,storage_scheme, Op::Update(key.clone(), &field, customer.updated_by.as_deref())).await; + let storage_scheme = decide_storage_scheme::<_, diesel_models::Customer>( + self, + storage_scheme, + Op::Update(key.clone(), &field, customer.updated_by.as_deref()), + ) + .await; let updated_object = match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -250,7 +259,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,diesel_models::Customer>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, diesel_models::Customer>(self, storage_scheme, Op::Find) + .await; let customer = match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -328,7 +339,12 @@ mod storage { .construct_new() .await .change_context(errors::StorageError::EncryptionError)?; - let storage_scheme = decide_storage_scheme::<_,diesel_models::Customer>(self,storage_scheme, Op::Insert).await; + let storage_scheme = decide_storage_scheme::<_, diesel_models::Customer>( + self, + storage_scheme, + Op::Insert, + ) + .await; new_customer.update_storage_scheme(storage_scheme); let create_customer = match storage_scheme { MerchantStorageScheme::PostgresOnly => { diff --git a/crates/router/src/db/mandate.rs b/crates/router/src/db/mandate.rs index 3e90be1b77bd..c9995d502c0d 100644 --- a/crates/router/src/db/mandate.rs +++ b/crates/router/src/db/mandate.rs @@ -57,7 +57,9 @@ mod storage { use error_stack::{report, ResultExt}; use redis_interface::HsetnxReply; use router_env::{instrument, tracing}; - use storage_impl::redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}; + use storage_impl::redis::kv_store::{ + decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey, + }; use super::MandateInterface; use crate::{ @@ -88,7 +90,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,diesel_models::Mandate>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, diesel_models::Mandate>(self, storage_scheme, Op::Find) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -132,7 +136,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,diesel_models::Mandate>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, diesel_models::Mandate>(self, storage_scheme, Op::Find) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -192,7 +198,12 @@ mod storage { mandate_id, }; let field = format!("mandate_{}", mandate_id); - let storage_scheme = decide_storage_scheme::<_,diesel_models::Mandate>(self,storage_scheme, Op::Update(key.clone(), &field,mandate.updated_by.as_deref())).await; + let storage_scheme = decide_storage_scheme::<_, diesel_models::Mandate>( + self, + storage_scheme, + Op::Update(key.clone(), &field, mandate.updated_by.as_deref()), + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { storage_types::Mandate::update_by_merchant_id_mandate_id( @@ -275,7 +286,12 @@ mod storage { storage_scheme: MerchantStorageScheme, ) -> CustomResult { let conn = connection::pg_connection_write(self).await?; - let storage_scheme = decide_storage_scheme::<_,diesel_models::Mandate>(self,storage_scheme, Op::Insert).await; + let storage_scheme = decide_storage_scheme::<_, diesel_models::Mandate>( + self, + storage_scheme, + Op::Insert, + ) + .await; mandate.update_storage_scheme(storage_scheme); match storage_scheme { MerchantStorageScheme::PostgresOnly => mandate @@ -612,7 +628,7 @@ impl MandateInterface for MockDb { metadata: mandate_new.metadata, connector_mandate_ids: mandate_new.connector_mandate_ids, merchant_connector_id: mandate_new.merchant_connector_id, - updated_by : mandate_new.updated_by, + updated_by: mandate_new.updated_by, }; mandates.push(mandate.clone()); Ok(mandate) diff --git a/crates/router/src/db/payment_method.rs b/crates/router/src/db/payment_method.rs index 02beb594d135..dc685ae49d32 100644 --- a/crates/router/src/db/payment_method.rs +++ b/crates/router/src/db/payment_method.rs @@ -71,7 +71,9 @@ mod storage { use error_stack::{report, ResultExt}; use redis_interface::HsetnxReply; use router_env::{instrument, tracing}; - use storage_impl::redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}; + use storage_impl::redis::kv_store::{ + decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey, + }; use super::PaymentMethodInterface; use crate::{ @@ -97,7 +99,12 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,storage_types::PaymentMethod>(self,storage_scheme, Op::Find).await; + let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>( + self, + storage_scheme, + Op::Find, + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -141,7 +148,12 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,storage_types::PaymentMethod>(self,storage_scheme, Op::Find).await; + let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>( + self, + storage_scheme, + Op::Find, + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -197,7 +209,12 @@ mod storage { mut payment_method_new: storage_types::PaymentMethodNew, storage_scheme: MerchantStorageScheme, ) -> CustomResult { - let storage_scheme = decide_storage_scheme::<_,storage_types::PaymentMethod>(self,storage_scheme, Op::Insert).await; + let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>( + self, + storage_scheme, + Op::Insert, + ) + .await; payment_method_new.update_storage_scheme(storage_scheme); match storage_scheme { MerchantStorageScheme::PostgresOnly => { @@ -287,19 +304,28 @@ mod storage { customer_id: &customer_id, }; let field = format!("payment_method_id_{}", payment_method.payment_method_id); - let storage_scheme = decide_storage_scheme::<_,storage_types::PaymentMethod>(self,storage_scheme, Op::Update(key.clone(), &field, payment_method.updated_by.as_deref())).await; + let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>( + self, + storage_scheme, + Op::Update(key.clone(), &field, payment_method.updated_by.as_deref()), + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { let conn = connection::pg_connection_write(self).await?; payment_method - .update_with_payment_method_id(&conn, payment_method_update.convert_to_payment_method_update(storage_scheme)) + .update_with_payment_method_id( + &conn, + payment_method_update.convert_to_payment_method_update(storage_scheme), + ) .await .map_err(|error| report!(errors::StorageError::from(error))) } MerchantStorageScheme::RedisKv => { let key_str = key.to_string(); - let p_update: PaymentMethodUpdateInternal = payment_method_update.convert_to_payment_method_update(storage_scheme); + let p_update: PaymentMethodUpdateInternal = + payment_method_update.convert_to_payment_method_update(storage_scheme); let updated_payment_method = p_update.clone().apply_changeset(payment_method.clone()); @@ -666,7 +692,7 @@ impl PaymentMethodInterface for MockDb { client_secret: payment_method_new.client_secret, network_transaction_id: payment_method_new.network_transaction_id, payment_method_billing_address: payment_method_new.payment_method_billing_address, - updated_by : payment_method_new.updated_by, + updated_by: payment_method_new.updated_by, }; payment_methods.push(payment_method.clone()); Ok(payment_method) diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs index 78cbd73f4f65..3b24dd3960e7 100644 --- a/crates/router/src/db/refund.rs +++ b/crates/router/src/db/refund.rs @@ -275,7 +275,9 @@ mod storage { use error_stack::{report, ResultExt}; use redis_interface::HsetnxReply; use router_env::{instrument, tracing}; - use storage_impl::redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}; + use storage_impl::redis::kv_store::{ + decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey, + }; use super::RefundInterface; use crate::{ @@ -305,7 +307,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find) + .await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => database_call().await, enums::MerchantStorageScheme::RedisKv => { @@ -342,7 +346,9 @@ mod storage { new: storage_types::RefundNew, storage_scheme: enums::MerchantStorageScheme, ) -> CustomResult { - let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(self,storage_scheme, Op::Insert).await; + let storage_scheme = + decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Insert) + .await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => { let conn = connection::pg_connection_write(self).await?; @@ -487,7 +493,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find) + .await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => database_call().await, enums::MerchantStorageScheme::RedisKv => { @@ -536,7 +544,12 @@ mod storage { payment_id: &payment_id, }; let field = format!("pa_{}_ref_{}", &this.attempt_id, &this.refund_id); - let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(self,storage_scheme, Op::Update(key.clone(), &field,Some(&this.updated_by))).await; + let storage_scheme = decide_storage_scheme::<_, storage_types::Refund>( + self, + storage_scheme, + Op::Update(key.clone(), &field, Some(&this.updated_by)), + ) + .await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => { let conn = connection::pg_connection_write(self).await?; @@ -592,7 +605,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find) + .await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => database_call().await, enums::MerchantStorageScheme::RedisKv => { @@ -642,7 +657,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find) + .await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => database_call().await, enums::MerchantStorageScheme::RedisKv => { @@ -691,7 +708,9 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,storage_types::Refund>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find) + .await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => database_call().await, enums::MerchantStorageScheme::RedisKv => { diff --git a/crates/router/src/db/reverse_lookup.rs b/crates/router/src/db/reverse_lookup.rs index 77e6b63695ed..fcf38ca420d0 100644 --- a/crates/router/src/db/reverse_lookup.rs +++ b/crates/router/src/db/reverse_lookup.rs @@ -69,7 +69,9 @@ mod storage { use error_stack::{report, ResultExt}; use redis_interface::SetnxReply; use router_env::{instrument, tracing}; - use storage_impl::redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}; + use storage_impl::redis::kv_store::{ + decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey, + }; use super::{ReverseLookupInterface, Store}; use crate::{ @@ -91,7 +93,8 @@ mod storage { new: ReverseLookupNew, storage_scheme: enums::MerchantStorageScheme, ) -> CustomResult { - let storage_scheme = decide_storage_scheme::<_,ReverseLookup>(self,storage_scheme, Op::Insert).await; + let storage_scheme = + decide_storage_scheme::<_, ReverseLookup>(self, storage_scheme, Op::Insert).await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => { let conn = connection::pg_connection_write(self).await?; @@ -151,7 +154,8 @@ mod storage { .await .map_err(|error| report!(errors::StorageError::from(error))) }; - let storage_scheme = decide_storage_scheme::<_,ReverseLookup>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, ReverseLookup>(self, storage_scheme, Op::Find).await; match storage_scheme { enums::MerchantStorageScheme::PostgresOnly => database_call().await, enums::MerchantStorageScheme::RedisKv => { diff --git a/crates/router/src/types/domain/customer.rs b/crates/router/src/types/domain/customer.rs index 419d8b8abe36..0e8ac32b4af3 100644 --- a/crates/router/src/types/domain/customer.rs +++ b/crates/router/src/types/domain/customer.rs @@ -23,7 +23,7 @@ pub struct Customer { pub connector_customer: Option, pub address_id: Option, pub default_payment_method_id: Option, - pub updated_by : Option, + pub updated_by: Option, } #[async_trait::async_trait] @@ -48,7 +48,7 @@ impl super::behaviour::Conversion for Customer { connector_customer: self.connector_customer, address_id: self.address_id, default_payment_method_id: self.default_payment_method_id, - updated_by : self.updated_by, + updated_by: self.updated_by, }) } @@ -77,7 +77,7 @@ impl super::behaviour::Conversion for Customer { connector_customer: item.connector_customer, address_id: item.address_id, default_payment_method_id: item.default_payment_method_id, - updated_by : item.updated_by, + updated_by: item.updated_by, }) } .await @@ -101,7 +101,7 @@ impl super::behaviour::Conversion for Customer { modified_at: now, connector_customer: self.connector_customer, address_id: self.address_id, - updated_by : self.updated_by, + updated_by: self.updated_by, }) } } diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 1e0ef77c6847..0963cd2b41e2 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -151,7 +151,7 @@ pub struct KVRouterStore { drainer_num_partitions: u8, ttl_for_kv: u32, pub request_id: Option, - soft_kill_mode : bool, + soft_kill_mode: bool, } #[async_trait::async_trait] @@ -162,7 +162,8 @@ where { type Config = (RouterStore, String, u8, u32, Option); async fn new(config: Self::Config, _test_transaction: bool) -> StorageResult { - let (router_store, drainer_stream_name, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = config; + let (router_store, drainer_stream_name, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = + config; Ok(Self::from_store( router_store, drainer_stream_name, @@ -193,7 +194,7 @@ impl KVRouterStore { drainer_stream_name: String, drainer_num_partitions: u8, ttl_for_kv: u32, - soft_kill : Option + soft_kill: Option, ) -> Self { let request_id = store.request_id.clone(); @@ -203,7 +204,7 @@ impl KVRouterStore { drainer_num_partitions, ttl_for_kv, request_id, - soft_kill_mode : soft_kill.unwrap_or(false) + soft_kill_mode: soft_kill.unwrap_or(false), } } diff --git a/crates/storage_impl/src/lookup.rs b/crates/storage_impl/src/lookup.rs index 7683a9dd317d..67b8635aba4a 100644 --- a/crates/storage_impl/src/lookup.rs +++ b/crates/storage_impl/src/lookup.rs @@ -12,7 +12,7 @@ use redis_interface::SetnxReply; use crate::{ diesel_error_to_data_error, errors::RedisErrorExt, - redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}, + redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey}, utils::{self, try_redis_get_else_try_database_get}, DatabaseStore, KVRouterStore, RouterStore, }; @@ -71,7 +71,8 @@ impl ReverseLookupInterface for KVRouterStore { new: DieselReverseLookupNew, storage_scheme: storage_enums::MerchantStorageScheme, ) -> CustomResult { - let storage_scheme = decide_storage_scheme::<_,DieselReverseLookup>(self,storage_scheme, Op::Insert).await; + let storage_scheme = + decide_storage_scheme::<_, DieselReverseLookup>(self, storage_scheme, Op::Insert).await; match storage_scheme { storage_enums::MerchantStorageScheme::PostgresOnly => { self.router_store @@ -125,7 +126,8 @@ impl ReverseLookupInterface for KVRouterStore { .get_lookup_by_lookup_id(id, storage_scheme) .await }; - let storage_scheme = decide_storage_scheme::<_,DieselReverseLookup>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselReverseLookup>(self, storage_scheme, Op::Find).await; match storage_scheme { storage_enums::MerchantStorageScheme::PostgresOnly => database_call().await, storage_enums::MerchantStorageScheme::RedisKv => { diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 316c4fd3e927..88387d7c1afd 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -31,7 +31,7 @@ use crate::{ diesel_error_to_data_error, errors::RedisErrorExt, lookup::ReverseLookupInterface, - redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}, + redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey}, utils::{pg_connection_read, pg_connection_write, try_redis_get_else_try_database_get}, DataModelExt, DatabaseStore, KVRouterStore, RouterStore, }; @@ -333,7 +333,9 @@ impl PaymentAttemptInterface for KVRouterStore { payment_attempt: PaymentAttemptNew, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Insert).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Insert) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -474,7 +476,12 @@ impl PaymentAttemptInterface for KVRouterStore { payment_id: &this.payment_id, }; let field = format!("pa_{}", this.attempt_id); - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Update(key.clone(), &field, Some(&this.updated_by))).await; + let storage_scheme = decide_storage_scheme::<_, DieselPaymentAttempt>( + self, + storage_scheme, + Op::Update(key.clone(), &field, Some(&this.updated_by)), + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -588,7 +595,8 @@ impl PaymentAttemptInterface for KVRouterStore { merchant_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -646,7 +654,8 @@ impl PaymentAttemptInterface for KVRouterStore { storage_scheme, ) }; - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -699,7 +708,8 @@ impl PaymentAttemptInterface for KVRouterStore { storage_scheme, ) }; - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -747,7 +757,8 @@ impl PaymentAttemptInterface for KVRouterStore { connector_txn_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -808,7 +819,8 @@ impl PaymentAttemptInterface for KVRouterStore { attempt_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -855,7 +867,8 @@ impl PaymentAttemptInterface for KVRouterStore { merchant_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -915,7 +928,8 @@ impl PaymentAttemptInterface for KVRouterStore { merchant_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -975,7 +989,8 @@ impl PaymentAttemptInterface for KVRouterStore { payment_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result, errors::StorageError> { - let storage_scheme = decide_storage_scheme::<_,DieselPaymentAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs index 0b538a753a78..ee1fdea64f2c 100644 --- a/crates/storage_impl/src/payments/payment_intent.rs +++ b/crates/storage_impl/src/payments/payment_intent.rs @@ -43,7 +43,7 @@ use crate::connection; use crate::{ diesel_error_to_data_error, errors::RedisErrorExt, - redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}, + redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey}, utils::{self, pg_connection_read, pg_connection_write}, DataModelExt, DatabaseStore, KVRouterStore, }; @@ -62,7 +62,8 @@ impl PaymentIntentInterface for KVRouterStore { merchant_id: &merchant_id, payment_id: &payment_id, }; - let storage_scheme = decide_storage_scheme::<_,DieselPaymentIntent>(self, storage_scheme,Op::Insert).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentIntent>(self, storage_scheme, Op::Insert).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -70,7 +71,7 @@ impl PaymentIntentInterface for KVRouterStore { .await } - MerchantStorageScheme::RedisKv => { + MerchantStorageScheme::RedisKv => { let key_str = key.to_string(); let created_intent = PaymentIntent { id: 0i32, @@ -162,7 +163,12 @@ impl PaymentIntentInterface for KVRouterStore { payment_id: &payment_id, }; let field = format!("pi_{}", this.payment_id); - let storage_scheme = decide_storage_scheme::<_,DieselPaymentIntent>(self,storage_scheme, Op::Update(key.clone(), &field, Some(&this.updated_by))).await; + let storage_scheme = decide_storage_scheme::<_, DieselPaymentIntent>( + self, + storage_scheme, + Op::Update(key.clone(), &field, Some(&this.updated_by)), + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -226,7 +232,8 @@ impl PaymentIntentInterface for KVRouterStore { er.change_context(new_err) }) }; - let storage_scheme = decide_storage_scheme::<_,DieselPaymentIntent>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPaymentIntent>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, diff --git a/crates/storage_impl/src/payouts/payout_attempt.rs b/crates/storage_impl/src/payouts/payout_attempt.rs index 17313481333c..91c1669db30f 100644 --- a/crates/storage_impl/src/payouts/payout_attempt.rs +++ b/crates/storage_impl/src/payouts/payout_attempt.rs @@ -29,7 +29,7 @@ use crate::{ diesel_error_to_data_error, errors::RedisErrorExt, lookup::ReverseLookupInterface, - redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}, + redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey}, utils::{self, pg_connection_read, pg_connection_write}, DataModelExt, DatabaseStore, KVRouterStore, }; @@ -43,7 +43,8 @@ impl PayoutAttemptInterface for KVRouterStore { payouts: &Payouts, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPayoutAttempt>(self,storage_scheme, Op::Insert).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPayoutAttempt>(self, storage_scheme, Op::Insert).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -142,7 +143,12 @@ impl PayoutAttemptInterface for KVRouterStore { payout_attempt_id: &this.payout_id, }; let field = format!("poa_{}", this.payout_attempt_id); - let storage_scheme = decide_storage_scheme::<_,DieselPayoutAttempt>(self,storage_scheme, Op::Update(key.clone(), &field, None)).await; + let storage_scheme = decide_storage_scheme::<_, DieselPayoutAttempt>( + self, + storage_scheme, + Op::Update(key.clone(), &field, None), + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -197,7 +203,8 @@ impl PayoutAttemptInterface for KVRouterStore { payout_attempt_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPayoutAttempt>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPayoutAttempt>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store diff --git a/crates/storage_impl/src/payouts/payouts.rs b/crates/storage_impl/src/payouts/payouts.rs index adf3503473fc..92835dee59cf 100644 --- a/crates/storage_impl/src/payouts/payouts.rs +++ b/crates/storage_impl/src/payouts/payouts.rs @@ -38,7 +38,7 @@ use crate::connection; use crate::{ diesel_error_to_data_error, errors::RedisErrorExt, - redis::kv_store::{kv_wrapper, KvOperation, PartitionKey, Op, decide_storage_scheme}, + redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey}, utils::{self, pg_connection_read, pg_connection_write}, DataModelExt, DatabaseStore, KVRouterStore, }; @@ -51,7 +51,8 @@ impl PayoutsInterface for KVRouterStore { new: PayoutsNew, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result { - let storage_scheme = decide_storage_scheme::<_,DieselPayouts>(self,storage_scheme, Op::Insert).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPayouts>(self, storage_scheme, Op::Insert).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store.insert_payout(new, storage_scheme).await @@ -134,7 +135,12 @@ impl PayoutsInterface for KVRouterStore { payout_id: &this.payout_id, }; let field = format!("po_{}", this.payout_id); - let storage_scheme = decide_storage_scheme::<_,DieselPayouts>(self,storage_scheme, Op::Update(key.clone(), &field,None)).await; + let storage_scheme = decide_storage_scheme::<_, DieselPayouts>( + self, + storage_scheme, + Op::Update(key.clone(), &field, None), + ) + .await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { self.router_store @@ -196,7 +202,8 @@ impl PayoutsInterface for KVRouterStore { er.change_context(new_err) }) }; - let storage_scheme = decide_storage_scheme::<_,DieselPayouts>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPayouts>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => database_call().await, MerchantStorageScheme::RedisKv => { @@ -239,7 +246,8 @@ impl PayoutsInterface for KVRouterStore { er.change_context(new_err) }) }; - let storage_scheme = decide_storage_scheme::<_,DieselPayouts>(self,storage_scheme, Op::Find).await; + let storage_scheme = + decide_storage_scheme::<_, DieselPayouts>(self, storage_scheme, Op::Find).await; match storage_scheme { MerchantStorageScheme::PostgresOnly => { let maybe_payouts = database_call().await?; diff --git a/crates/storage_impl/src/redis/kv_store.rs b/crates/storage_impl/src/redis/kv_store.rs index e82d4f38fbf8..c39e67eb841b 100644 --- a/crates/storage_impl/src/redis/kv_store.rs +++ b/crates/storage_impl/src/redis/kv_store.rs @@ -1,12 +1,13 @@ use std::{fmt::Debug, sync::Arc}; use common_utils::errors::CustomResult; +use diesel_models::enums::MerchantStorageScheme; use error_stack::report; use redis_interface::errors::RedisError; use router_derive::TryGetEnumVariant; use router_env::logger; use serde::de; -use diesel_models::enums::MerchantStorageScheme; + use crate::{metrics, store::kv::TypedSql, KVRouterStore, UniqueConstraints}; pub trait KvStorePartition { @@ -237,18 +238,20 @@ where }) } -pub enum Op<'a>{ +pub enum Op<'a> { Insert, Update(PartitionKey<'a>, &'a str, Option<&'a str>), Find, } impl<'a> std::fmt::Display for Op<'a> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result{ - match self{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { Op::Insert => f.write_str("insert"), Op::Find => f.write_str("find"), - Op::Update(p_key, _, updated_by) => f.write_str(&format!("update_{} for updated_by_{:?}", p_key, updated_by)), + Op::Update(p_key, _, updated_by) => { + f.write_str(&format!("update_{} for updated_by_{:?}", p_key, updated_by)) + } } } } @@ -259,8 +262,13 @@ pub async fn decide_storage_scheme<'a, T, D>( operation: Op<'a>, ) -> MerchantStorageScheme where - D : de::DeserializeOwned + serde::Serialize + Debug + KvStorePartition + UniqueConstraints + Sync, - T : crate::database::store::DatabaseStore, + D: de::DeserializeOwned + + serde::Serialize + + Debug + + KvStorePartition + + UniqueConstraints + + Sync, + T: crate::database::store::DatabaseStore, { if store.soft_kill_mode { let ops = operation.to_string(); @@ -275,7 +283,7 @@ where Ok(_) => { metrics::KV_SOFT_KILL_ACTIVE_UPDATE.add(&metrics::CONTEXT, 1, &[]); MerchantStorageScheme::RedisKv - }, + } Err(_) => MerchantStorageScheme::PostgresOnly, } } @@ -285,12 +293,9 @@ where let type_name = std::any::type_name::(); logger::info!(soft_kill_mode = "decide_storage_scheme", decided_scheme = %updated_scheme, configured_scheme = %storage_scheme,entity = %type_name, operation = %ops); - + updated_scheme - } - else { + } else { storage_scheme } - - -} \ No newline at end of file +}