feat(router): add requeue support for payments and fix duplicate entry error in process tracker for requeued payments (#1567)

This commit is contained in:
Sai Harsha Vardhan
2023-07-03 12:56:01 +05:30
committed by GitHub
parent 7489c870d9
commit b967d23251
18 changed files with 133 additions and 22 deletions

View File

@ -763,6 +763,7 @@ pub async fn add_domain_task_to_pt<Op>(
operation: &Op,
state: &AppState,
payment_attempt: &storage::PaymentAttempt,
requeue: bool,
) -> CustomResult<(), errors::ApiErrorResponse>
where
Op: std::fmt::Debug,
@ -786,12 +787,21 @@ where
match schedule_time {
Some(stime) => {
scheduler_metrics::TASKS_ADDED_COUNT.add(&metrics::CONTEXT, 1, &[]); // Metrics
super::add_process_sync_task(&*state.store, payment_attempt, stime)
.await
.into_report()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while adding task to process tracker")
if !requeue {
scheduler_metrics::TASKS_ADDED_COUNT.add(&metrics::CONTEXT, 1, &[]); // Metrics
super::add_process_sync_task(&*state.store, payment_attempt, stime)
.await
.into_report()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while adding task to process tracker")
} else {
scheduler_metrics::TASKS_RESET_COUNT.add(&metrics::CONTEXT, 1, &[]); // Metrics
super::reset_process_sync_task(&*state.store, payment_attempt, stime)
.await
.into_report()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while updating task in process tracker")
}
}
None => Ok(()),
}
@ -2155,7 +2165,10 @@ pub fn get_attempt_type(
) -> RouterResult<AttemptType> {
match payment_intent.status {
enums::IntentStatus::Failed => {
if request.manual_retry {
if matches!(
request.retry_action,
Some(api_models::enums::RetryAction::ManualRetry)
) {
match payment_attempt.status {
enums::AttemptStatus::Started
| enums::AttemptStatus::AuthenticationPending