From d68d8335b2272cdc7b7789b2dd75b07226ff0b43 Mon Sep 17 00:00:00 2001 From: dead8309 Date: Fri, 11 Oct 2024 14:50:42 +0530 Subject: [PATCH] feat(backend): make payment retry attempts configurable via env - Closes #3017 - rename config variable to a proper name --- packages/backend/src/config/app.ts | 3 ++- packages/backend/src/index.ts | 1 + .../backend/src/open_payments/payment/outgoing/service.ts | 2 ++ .../backend/src/open_payments/payment/outgoing/worker.ts | 7 ++++--- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/config/app.ts b/packages/backend/src/config/app.ts index 29a3c7070a..94dc19c19c 100644 --- a/packages/backend/src/config/app.ts +++ b/packages/backend/src/config/app.ts @@ -187,7 +187,8 @@ export const Config = { 'INCOMING_PAYMENT_EXPIRY_MAX_MS', 2592000000 ), // 30 days - enableSpspPaymentPointers: envBool('ENABLE_SPSP_PAYMENT_POINTERS', true) + enableSpspPaymentPointers: envBool('ENABLE_SPSP_PAYMENT_POINTERS', true), + maxOutgoingPaymentRetryAttempts: envInt('MAX_OUTGOING_PAYMENT_RETRY_ATTEMPTS', 5) } function parseRedisTlsConfig( diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index dfa64c0ef4..a178e8b345 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -464,6 +464,7 @@ export function initIocContainer( container.singleton('outgoingPaymentService', async (deps) => { return await createOutgoingPaymentService({ + config: await deps.use('config'), logger: await deps.use('logger'), knex: await deps.use('knex'), accountingService: await deps.use('accountingService'), diff --git a/packages/backend/src/open_payments/payment/outgoing/service.ts b/packages/backend/src/open_payments/payment/outgoing/service.ts index 336444e518..2c9ad6043f 100644 --- a/packages/backend/src/open_payments/payment/outgoing/service.ts +++ b/packages/backend/src/open_payments/payment/outgoing/service.ts @@ -42,6 +42,7 @@ import { QuoteService } from '../../quote/service' import { isQuoteError } from '../../quote/errors' import { Pagination, SortOrder } from '../../../shared/baseModel' import { FilterString } from '../../../shared/filters' +import { IAppConfig } from '../../../config/app' export interface OutgoingPaymentService extends WalletAddressSubresourceService { @@ -59,6 +60,7 @@ export interface OutgoingPaymentService } export interface ServiceDependencies extends BaseService { + config: IAppConfig knex: TransactionOrKnex accountingService: AccountingService receiverService: ReceiverService diff --git a/packages/backend/src/open_payments/payment/outgoing/worker.ts b/packages/backend/src/open_payments/payment/outgoing/worker.ts index 0df698f960..9ca47b8938 100644 --- a/packages/backend/src/open_payments/payment/outgoing/worker.ts +++ b/packages/backend/src/open_payments/payment/outgoing/worker.ts @@ -10,8 +10,6 @@ import { trace, Span } from '@opentelemetry/api' // First retry waits 10 seconds, second retry waits 20 (more) seconds, etc. export const RETRY_BACKOFF_SECONDS = 10 -const MAX_STATE_ATTEMPTS = 5 - // Returns the id of the processed payment (if any). export async function processPendingPayment( deps_: ServiceDependencies @@ -94,7 +92,10 @@ async function onLifecycleError( const error = typeof err === 'string' ? err : err.message const stateAttempts = payment.stateAttempts + 1 - if (stateAttempts < MAX_STATE_ATTEMPTS && isRetryableError(err)) { + if ( + stateAttempts < deps.config.maxOutgoingPaymentRetryAttempts && + isRetryableError(err) + ) { deps.logger.warn( { state: payment.state, error, stateAttempts }, 'payment lifecycle failed; retrying'