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

refactor(currency_conversion): re frame the currency_conversion crate to make api calls on background thread #6906

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 4 additions & 7 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,10 @@ max_feed_count = 200 # The maximum number of frames that will be fe

# This section provides configs for currency conversion api
[forex_api]
call_delay = 21600 # Api calls are made after every 6 hrs
local_fetch_retry_count = 5 # Fetch from Local cache has retry count as 5
local_fetch_retry_delay = 1000 # Retry delay for checking write condition
api_timeout = 20000 # Api timeouts once it crosses 20000 ms
api_key = "YOUR API KEY HERE" # Api key for making request to foreign exchange Api
fallback_api_key = "YOUR API KEY" # Api key for the fallback service
redis_lock_timeout = 26000 # Redis remains write locked for 26000 ms once the acquire_redis_lock is called
call_delay = 21600 # Expiration time for data in cache as well as redis in seconds
api_key = "" # Api key for making request to foreign exchange Api
fallback_api_key = "" # Api key for the fallback service
redis_lock_timeout = 100 # Redis remains write locked for 100 s once the acquire_redis_lock is called

# Logging configuration. Logging can be either to file or console or both.

Expand Down
11 changes: 4 additions & 7 deletions config/deployments/env_specific.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,10 @@ bucket_name = "bucket" # The AWS S3 bucket name for file storage

# This section provides configs for currency conversion api
[forex_api]
call_delay = 21600 # Api calls are made after every 6 hrs
local_fetch_retry_count = 5 # Fetch from Local cache has retry count as 5
local_fetch_retry_delay = 1000 # Retry delay for checking write condition
api_timeout = 20000 # Api timeouts once it crosses 20000 ms
api_key = "YOUR API KEY HERE" # Api key for making request to foreign exchange Api
fallback_api_key = "YOUR API KEY" # Api key for the fallback service
redis_lock_timeout = 26000 # Redis remains write locked for 26000 ms once the acquire_redis_lock is called
call_delay = 21600 # Expiration time for data in cache as well as redis in seconds
api_key = "" # Api key for making request to foreign exchange Api
fallback_api_key = "" # Api key for the fallback service
redis_lock_timeout = 100 # Redis remains write locked for 100 s once the acquire_redis_lock is called

[jwekey] # 3 priv/pub key pair
vault_encryption_key = "" # public key in pem format, corresponding private key in rust locker
Expand Down
9 changes: 3 additions & 6 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ ttl_for_storage_in_secs = 220752000

[forex_api]
call_delay = 21600
local_fetch_retry_count = 5
local_fetch_retry_delay = 1000
api_timeout = 20000
api_key = "YOUR API KEY HERE"
fallback_api_key = "YOUR API KEY HERE"
redis_lock_timeout = 26000
api_key = ""
fallback_api_key = ""
redis_lock_timeout = 100

[jwekey]
vault_encryption_key = ""
Expand Down
9 changes: 3 additions & 6 deletions config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ pool_size = 5

[forex_api]
call_delay = 21600
local_fetch_retry_count = 5
local_fetch_retry_delay = 1000
api_timeout = 20000
api_key = "YOUR API KEY HERE"
fallback_api_key = "YOUR API KEY HERE"
redis_lock_timeout = 26000
api_key = ""
fallback_api_key = ""
redis_lock_timeout = 100

[replica_database]
username = "db_user"
Expand Down
6 changes: 3 additions & 3 deletions crates/analytics/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ To configure the Forex APIs, update the `config/development.toml` or `config/doc

```toml
[forex_api]
api_key = "YOUR API KEY HERE" # Replace the placeholder with your Primary API Key
fallback_api_key = "YOUR API KEY HERE" # Replace the placeholder with your Fallback API Key
api_key = "" # Replace the placeholder with your Primary API Key
fallback_api_key = "" # Replace the placeholder with your Fallback API Key
```
### Important Note
```bash
Expand Down Expand Up @@ -159,4 +159,4 @@ To view the data on the OpenSearch dashboard perform the following steps:
- Select a time field that will be used for time-based queries
- Save the index pattern

Now, head on to `Discover` under the `OpenSearch Dashboards` tab, to select the newly created index pattern and query the data
Now, head on to `Discover` under the `OpenSearch Dashboards` tab, to select the newly created index pattern and query the data
9 changes: 2 additions & 7 deletions crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,11 @@ pub struct PaymentLink {
#[derive(Debug, Deserialize, Clone, Default)]
#[serde(default)]
pub struct ForexApi {
pub local_fetch_retry_count: u64,
pub api_key: Secret<String>,
pub fallback_api_key: Secret<String>,
/// in ms
/// in s
pub call_delay: i64,
prajjwalkumar17 marked this conversation as resolved.
Show resolved Hide resolved
/// in ms
pub local_fetch_retry_delay: u64,
/// in ms
pub api_timeout: u64,
/// in ms
/// in s
pub redis_lock_timeout: u64,
}

Expand Down
26 changes: 8 additions & 18 deletions crates/router/src/core/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ pub async fn retrieve_forex(
) -> CustomResult<ApplicationResponse<currency::FxExchangeRatesCacheEntry>, ApiErrorResponse> {
let forex_api = state.conf.forex_api.get_inner();
Ok(ApplicationResponse::Json(
get_forex_rates(
&state,
forex_api.call_delay,
forex_api.local_fetch_retry_delay,
forex_api.local_fetch_retry_count,
)
.await
.change_context(ApiErrorResponse::GenericNotFoundError {
message: "Unable to fetch forex rates".to_string(),
})?,
get_forex_rates(&state, forex_api.call_delay)
.await
.change_context(ApiErrorResponse::GenericNotFoundError {
message: "Unable to fetch forex rates".to_string(),
})?,
))
}

Expand Down Expand Up @@ -53,14 +48,9 @@ pub async fn get_forex_exchange_rates(
state: SessionState,
) -> CustomResult<ExchangeRates, AnalyticsError> {
let forex_api = state.conf.forex_api.get_inner();
let rates = get_forex_rates(
&state,
forex_api.call_delay,
forex_api.local_fetch_retry_delay,
forex_api.local_fetch_retry_count,
)
.await
.change_context(AnalyticsError::ForexFetchFailed)?;
let rates = get_forex_rates(&state, forex_api.call_delay)
.await
.change_context(AnalyticsError::ForexFetchFailed)?;

Ok((*rates.data).clone())
}
Loading
Loading