From 48742d61c02b3d62a43974c4c40b12bd467fd817 Mon Sep 17 00:00:00 2001 From: Ankur Dubey Date: Wed, 19 Jun 2024 13:43:20 +0400 Subject: [PATCH] temp: fix build --- crates/routing_engine/src/indexer.rs | 17 ++++++++++------- crates/storage/src/lib.rs | 6 ++++-- crates/storage/src/redis.rs | 10 ++++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/routing_engine/src/indexer.rs b/crates/routing_engine/src/indexer.rs index 5b33d8a..45539b2 100644 --- a/crates/routing_engine/src/indexer.rs +++ b/crates/routing_engine/src/indexer.rs @@ -91,7 +91,7 @@ impl< Ok::< estimator::DataPoint, - IndexerErrors, + IndexerErrors, >(estimator::DataPoint { x: input_value_in_usd, y: fee_in_usd, @@ -102,7 +102,7 @@ impl< .collect::, - IndexerErrors, + IndexerErrors, >, >>() .await @@ -125,7 +125,7 @@ impl< >( &mut self, values: Vec<(&&BucketConfig, &Estimator)>, - ) -> Result<(), IndexerErrors> { + ) -> Result<(), IndexerErrors> { let values_transformed = values .iter() .map(|(k, v)| { @@ -150,7 +150,7 @@ impl< &mut self, ) -> Result< HashMap<&'config BucketConfig, Estimator>, - IndexerErrors, + IndexerErrors, > { // Build Estimators let estimator_map: HashMap<&BucketConfig, Estimator> = @@ -189,6 +189,7 @@ enum IndexerErrors< T: token_price::TokenPriceProvider, S: source::RouteSource, R: storage::RoutingModelStore, + U: storage::MessageQueue, > { #[display(fmt = "Route build error: {}", _0)] RouteBuildError(RouteError), @@ -206,7 +207,7 @@ enum IndexerErrors< PublishEstimatorErrors(Vec), #[display(fmt = "Indexer update message error: {}", _0)] - PublishIndexerUpdateMessageError(String), + PublishIndexerUpdateMessageError(U::Error), } #[cfg(test)] @@ -246,11 +247,13 @@ mod tests { struct ProducerStub; impl MessageQueue for ProducerStub { - async fn publish(&mut self, topic: &str, message: &str) -> Result<(), String> { + type Error = (); + + async fn publish(&mut self, topic: &str, message: &str) -> Result<(), ()> { Ok(()) } - async fn subscribe(&mut self, topic: &str) -> Result { + async fn subscribe(&mut self, topic: &str) -> Result { Ok("Subscribed".to_string()) } } diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index 881b84a..d76172c 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -15,7 +15,9 @@ pub trait RoutingModelStore { } pub trait MessageQueue { - async fn publish(&mut self, topic: &str, message: &str) -> Result<(), String>; + type Error: Debug; + + async fn publish(&mut self, topic: &str, message: &str) -> Result<(), Self::Error>; - async fn subscribe(&mut self, topic: &str) -> Result; + async fn subscribe(&mut self, topic: &str) -> Result; } diff --git a/crates/storage/src/redis.rs b/crates/storage/src/redis.rs index abe9266..409b402 100644 --- a/crates/storage/src/redis.rs +++ b/crates/storage/src/redis.rs @@ -1,5 +1,5 @@ use redis; -use redis::{aio, AsyncCommands}; +use redis::{aio, AsyncCommands, Commands}; use redis::RedisError; use thiserror::Error; @@ -41,11 +41,13 @@ impl RoutingModelStore for RedisClient { } impl MessageQueue for RedisClient { - async fn publish(&mut self, topic: &str, message: &str) -> Result<(), String> { - todo!() + type Error = RedisClientError; + + async fn publish(&mut self, topic: &str, message: &str) -> Result<(), Self::Error> { + self.connection.publish(topic, message).await.map_err(RedisClientError::RedisLibraryError) } - async fn subscribe(&mut self, topic: &str) -> Result { + async fn subscribe(&mut self, topic: &str) -> Result { todo!() } }