-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix(analytics): retry implementation for forex crate call #7280
base: main
Are you sure you want to change the base?
Conversation
Changed Files
|
crates/router/src/core/currency.rs
Outdated
Err(error) => { | ||
if attempt >= max_attempts { | ||
logger::error!("Failed to fetch forex rates after {max_attempts} attempts"); | ||
return Err(error.change_context(AnalyticsError::ForexFetchFailed)); | ||
} | ||
logger::warn!("Forex rates fetch failed, retrying in {attempt} seconds"); | ||
tokio::time::sleep(std::time::Duration::from_secs(attempt)).await; | ||
attempt += 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of retrying on all error cases, should we match on the error type and retry only if its a retryable error? Something like failing to attain redis lock could be retried but incorrect forex creds error cannot be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redis lock is not there now on the function which we are invoking
crates/router/src/core/currency.rs
Outdated
let rates = get_forex_rates(&state, forex_api.call_delay) | ||
.await | ||
.change_context(AnalyticsError::ForexFetchFailed)?; | ||
let max_attempts = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this max_attempt be hard coded or should this be a config option, if hardcoded can we maintain in the consts.rs
… into forex_analytics_retry
Type of Change
Description
Implementing a retry logic for forex crate call with linear time increment in retry counter
Additional Changes
crates/router/src/core/currency.rs
Motivation and Context
This was required as the Analytics API was returning 5xx when forex was returning error which would eventually resolve on retry
How did you test it?
Added logs for the same
Checklist
cargo +nightly fmt --all
cargo clippy