Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): make payment retry attempts configurable via env #3028

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/backend/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ 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
Loading