diff --git a/bothan-binance/src/service.rs b/bothan-binance/src/service.rs index 51b10e10..84528530 100644 --- a/bothan-binance/src/service.rs +++ b/bothan-binance/src/service.rs @@ -179,19 +179,15 @@ async fn save_datum(data: &Data, cache: &Arc>) { timestamp: ticker.event_time, }; info!("received prices: {:?}", price_data); - match cache.set_data(ticker.symbol.clone(), price_data).await { - Ok(_) => { - info!("successfully set {} in cache", ticker.symbol); - } - Err(CacheError::PendingNotSet) => { - warn!( - "received data for id that was not pending: {}", - ticker.symbol - ); - } - Err(e) => { - error!("error setting data in cache: {:?}", e) - } + let id = price_data.id.clone(); + if cache + .set_data(ticker.symbol.clone(), price_data) + .await + .is_err() + { + warn!("unexpected request to set data for id: {}", id); + } else { + info!("set price for id {}", id); } } } diff --git a/bothan-coingecko/Cargo.toml b/bothan-coingecko/Cargo.toml index 6216bb64..8f31d22b 100644 --- a/bothan-coingecko/Cargo.toml +++ b/bothan-coingecko/Cargo.toml @@ -17,7 +17,7 @@ reqwest = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } -serde ={ workspace = true } +serde = { workspace = true } tokio = { workspace = true } diff --git a/bothan-coingecko/src/api/rest.rs b/bothan-coingecko/src/api/rest.rs index 54bf1e56..ae7b9249 100644 --- a/bothan-coingecko/src/api/rest.rs +++ b/bothan-coingecko/src/api/rest.rs @@ -82,7 +82,7 @@ pub(crate) mod test { (server, api) } - pub(crate) trait MockGecko { + pub(crate) trait MockCoinGecko { fn set_successful_coin_list(&mut self, coin_list: &[Coin]) -> Mock; fn set_failed_coin_list(&mut self) -> Mock; fn set_successful_coins_market(&mut self, ids: &[&str], market: &[Market]) -> Vec; @@ -94,7 +94,7 @@ pub(crate) mod test { fn set_failed_coins_market(&mut self, ids: &[&str]) -> Mock; } - impl MockGecko for ServerGuard { + impl MockCoinGecko for ServerGuard { fn set_successful_coin_list(&mut self, coin_list: &[Coin]) -> Mock { self.mock("GET", "/coins/list") .with_status(200) diff --git a/bothan-coingecko/src/service.rs b/bothan-coingecko/src/service.rs index 6dd48ecb..1d31a434 100644 --- a/bothan-coingecko/src/service.rs +++ b/bothan-coingecko/src/service.rs @@ -3,15 +3,15 @@ use std::sync::Arc; use chrono::NaiveDateTime; use futures::future::join_all; +use futures::stream::FuturesUnordered; use tokio::select; use tokio::sync::RwLock; use tokio::time::{interval, Duration, Interval}; -use tracing::warn; +use tracing::{info, 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; use crate::api::types::Market; use crate::api::CoinGeckoRestAPI; @@ -73,7 +73,7 @@ impl Service for CoinGeckoService { } } Err(CacheError::Invalid) => Err(ServiceError::InvalidSymbol), - Err(_) => Err(ServiceError::Pending), + Err(e) => panic!("unexpected error: {}", e), // This should never happen }) .collect(); @@ -172,7 +172,7 @@ async fn update_coin_list( let mut locked = coin_list.write().await; *locked = new_coin_set; } else { - warn!("Failed to get coin list"); + warn!("failed to get coin list"); } } @@ -180,10 +180,12 @@ async fn process_market_data(market: &Market, cache: &Arc>) { if let Ok(price_data) = parse_market(market) { let id = price_data.id.clone(); if cache.set_data(id.clone(), price_data).await.is_err() { - warn!("Unexpected request to set data for id: {}", id); + warn!("unexpected request to set data for id: {}", id); + } else { + info!("set price for id {}", id); } } else { - warn!("Failed to parse date time"); + warn!("failed to parse date time"); } } @@ -205,7 +207,7 @@ fn parse_market(market: &Market) -> Result { mod test { use mockito::ServerGuard; - use crate::api::rest::test::{setup as api_setup, MockGecko}; + use crate::api::rest::test::{setup as api_setup, MockCoinGecko}; use crate::api::types::Coin; use super::*;