Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(scheduler): join frequency and count in `RetryMapping` (#4313)
Sakil Mostak33351953baf3
diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rsindex 4b35e4d73b..932a06bae6 100644--- a/crates/router/src/workflows/payment_sync.rs+++ b/crates/router/src/workflows/payment_sync.rs@@ -300,7 +300,7 @@ mod tests {vec![schedule_time_delta, first_retry_time_delta],vec![cpt_default.start_after,- *cpt_default.frequency.first().unwrap()+ cpt_default.frequencies.first().unwrap().0]);}diff --git a/crates/scheduler/src/consumer/types/process_data.rs b/crates/scheduler/src/consumer/types/process_data.rsindex 267305c37f..98d0fe530e 100644--- a/crates/scheduler/src/consumer/types/process_data.rs+++ b/crates/scheduler/src/consumer/types/process_data.rs@@ -6,8 +6,7 @@ use serde::{Deserialize, Serialize};#[derive(Serialize, Deserialize, Clone, Debug)]pub struct RetryMapping {pub start_after: i32,- pub frequency: Vec<i32>,- pub count: Vec<i32>,+ pub frequencies: Vec<(i32, i32)>, // (frequency, count)}#[derive(Serialize, Deserialize)]@@ -23,8 +22,7 @@ impl Default for ConnectorPTMapping {custom_merchant_mapping: HashMap::new(),default_mapping: RetryMapping {start_after: 60,- frequency: vec![300],- count: vec![5],+ frequencies: vec![(300, 5)],},max_retries_count: 5,}@@ -44,8 +42,7 @@ impl Default for PaymentMethodsPTMapping {custom_pm_mapping: HashMap::new(),default_mapping: RetryMapping {start_after: 900,- frequency: vec![300],- count: vec![5],+ frequencies: vec![(300, 5)],},max_retries_count: 5,}@@ -70,21 +67,15 @@ impl Default for OutgoingWebhookRetryProcessTrackerMapping {// 1st attempt happens after 1 minutestart_after: 60,- frequency: vec![+ frequencies: vec![// 2nd and 3rd attempts happen at intervals of 5 minutes each- 60 * 5,+ (60 * 5, 2),// 4th, 5th, 6th, 7th and 8th attempts happen at intervals of 10 minutes each- 60 * 10,+ (60 * 10, 5),// 9th, 10th, 11th, 12th and 13th attempts happen at intervals of 1 hour each- 60 * 60,+ (60 * 60, 5),// 14th, 15th and 16th attempts happen at intervals of 6 hours each- 60 * 60 * 6,- ],- count: vec![- 2, // 2nd and 3rd attempts- 5, // 4th, 5th, 6th, 7th and 8th attempts- 5, // 9th, 10th, 11th, 12th and 13th attempts- 3, // 14th, 15th and 16th attempts+ (60 * 60 * 6, 3),],},custom_merchant_mapping: HashMap::new(),diff --git a/crates/scheduler/src/utils.rs b/crates/scheduler/src/utils.rsindex 48d02f7fce..11924dd1be 100644--- a/crates/scheduler/src/utils.rs+++ b/crates/scheduler/src/utils.rs@@ -315,10 +315,7 @@ pub fn get_schedule_time(if retry_count == 0 {Some(mapping.start_after)} else {- get_delay(- retry_count,- mapping.count.iter().zip(mapping.frequency.iter()),- )+ get_delay(retry_count, &mapping.frequencies)}}@@ -335,10 +332,7 @@ pub fn get_pm_schedule_time(if retry_count == 0 {Some(mapping.start_after)} else {- get_delay(- retry_count,- mapping.count.iter().zip(mapping.frequency.iter()),- )+ get_delay(retry_count, &mapping.frequencies)}}@@ -356,25 +350,22 @@ pub fn get_outgoing_webhook_retry_schedule_time(if retry_count == 0 {Some(retry_mapping.start_after)} else {- get_delay(- retry_count,- retry_mapping- .count- .iter()- .zip(retry_mapping.frequency.iter()),- )+ get_delay(retry_count, &retry_mapping.frequencies)}}/// Get the delay based on the retry count-fn get_delay<'a>(retry_count: i32, array: impl Iterator<Item = (&'a i32, &'a i32)>) -> Option<i32> {+fn get_delay<'a>(+ retry_count: i32,+ frequencies: impl IntoIterator<Item = &'a (i32, i32)>,+) -> Option<i32> {// Preferably, fix this by using unsigned intsif retry_count <= 0 {return None;}let mut cumulative_count = 0;- for (&count, &frequency) in array {+ for &(frequency, count) in frequencies.into_iter() {cumulative_count += count;if cumulative_count >= retry_count {return Some(frequency);@@ -423,8 +414,7 @@ mod tests {#[test]fn test_get_delay() {- let count = [10, 5, 3, 2];- let frequency = [300, 600, 1800, 3600];+ let frequency_count = vec![(300, 10), (600, 5), (1800, 3), (3600, 2)];let retry_counts_and_expected_delays = [(-4, None),@@ -442,7 +432,7 @@ mod tests {];for (retry_count, expected_delay) in retry_counts_and_expected_delays {- let delay = get_delay(retry_count, count.iter().zip(frequency.iter()));+ let delay = get_delay(retry_count, &frequency_count);assert_eq!(delay, expected_delay,