Skip to content

Commit

Permalink
feat(backend): make payment retry attempts configurable via env
Browse files Browse the repository at this point in the history
- Closes #3017
- rename config variable to a proper name
  • Loading branch information
dead8309 committed Oct 14, 2024
1 parent 254784c commit d68d833
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/backend/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OutgoingPayment> {
Expand All @@ -59,6 +60,7 @@ export interface OutgoingPaymentService
}

export interface ServiceDependencies extends BaseService {
config: IAppConfig
knex: TransactionOrKnex
accountingService: AccountingService
receiverService: ReceiverService
Expand Down
7 changes: 4 additions & 3 deletions packages/backend/src/open_payments/payment/outgoing/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit d68d833

Please sign in to comment.