Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
warittornc committed Feb 23, 2024
1 parent 3b58fef commit f3aa56c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions bothan-coingecko/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license.workspace = true
[dependencies]
url = "2.5.0"
chrono = "0.4.34"
futures = "0.3.30"

bothan-core = { workspace = true }
async-trait = { workspace = true }
Expand Down
9 changes: 7 additions & 2 deletions bothan-coingecko/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashSet;
use std::sync::Arc;

use chrono::NaiveDateTime;
use futures::future::join_all;
use tokio::select;
use tokio::sync::RwLock;
use tokio::time::{interval, Duration, Interval};
Expand All @@ -10,6 +11,7 @@ use tracing::warn;
use bothan_core::cache::{Cache, Error as CacheError};
use bothan_core::service::{Error as ServiceError, Service, ServiceResult};
use bothan_core::types::PriceData;
use futures::stream::{FuturesUnordered, StreamExt};

use crate::api::types::Market;
use crate::api::CoinGeckoRestAPI;
Expand Down Expand Up @@ -121,17 +123,20 @@ async fn update_price_data(
keys.len().div_ceil(page_size)
};

let tasks = FuturesUnordered::new();
for page in 1..=pages {
if let Some(interval) = delay.as_mut() {
interval.tick().await;
}

let cloned_api = rest_api.clone();
let cloned_cache = cache.clone();
tokio::spawn(async move {
tasks.push(tokio::spawn(async move {
update_price_data_from_api(&cloned_api, &cloned_cache, page, page_size).await;
});
}));
}

join_all(tasks).await;
}

async fn update_price_data_from_api(
Expand Down

0 comments on commit f3aa56c

Please sign in to comment.