From 9952e3adf914e1027125cbefb91122ace175e41c Mon Sep 17 00:00:00 2001 From: Chris Sellers Date: Sun, 26 Nov 2023 12:30:17 +1100 Subject: [PATCH] Refine RedisCacheDatabase scaffolding in Rust --- nautilus_core/infrastructure/src/cache.rs | 2 +- nautilus_core/infrastructure/src/python/cache.rs | 6 +++--- nautilus_core/infrastructure/src/redis.rs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nautilus_core/infrastructure/src/cache.rs b/nautilus_core/infrastructure/src/cache.rs index eff851a47dfe..a4e7ad07876c 100644 --- a/nautilus_core/infrastructure/src/cache.rs +++ b/nautilus_core/infrastructure/src/cache.rs @@ -36,7 +36,7 @@ pub trait CacheDatabase { fn new(trader_id: TraderId, config: HashMap) -> Result; fn read(&mut self, op_type: String) -> Result>>; - fn write(&mut self, op_type: String, payload: Vec>) -> Result; + fn write(&mut self, op_type: String, payload: Vec>) -> Result<(), String>; fn handle_ops( trader_id: TraderId, config: HashMap, diff --git a/nautilus_core/infrastructure/src/python/cache.rs b/nautilus_core/infrastructure/src/python/cache.rs index 18ba0ef8322e..878b590b60e4 100644 --- a/nautilus_core/infrastructure/src/python/cache.rs +++ b/nautilus_core/infrastructure/src/python/cache.rs @@ -48,15 +48,15 @@ impl RedisCacheDatabase { #[pyo3(name = "read")] fn py_read(&mut self, op_type: String) -> PyResult>> { match self.read(op_type) { - Ok(result) => Ok(result), + Ok(payload) => Ok(payload), Err(e) => Err(to_pyruntime_err(e)), } } #[pyo3(name = "write")] - fn py_write(&mut self, op_type: String, payload: Vec>) -> PyResult { + fn py_write(&mut self, op_type: String, payload: Vec>) -> PyResult<()> { match self.write(op_type, payload) { - Ok(ok) => Ok(ok), + Ok(_) => Ok(()), Err(e) => Err(to_pyvalue_err(e)), } } diff --git a/nautilus_core/infrastructure/src/redis.rs b/nautilus_core/infrastructure/src/redis.rs index 0f618d92e1ca..9dd3406d932f 100644 --- a/nautilus_core/infrastructure/src/redis.rs +++ b/nautilus_core/infrastructure/src/redis.rs @@ -19,7 +19,7 @@ use std::{ thread, }; -use anyhow::{anyhow, Result}; +use anyhow::Result; use nautilus_common::redis::get_redis_url; use nautilus_model::identifiers::trader_id::TraderId; use pyo3::prelude::*; @@ -64,11 +64,11 @@ impl CacheDatabase for RedisCacheDatabase { Ok(result) } - fn write(&mut self, op_type: String, payload: Vec>) -> Result { + fn write(&mut self, op_type: String, payload: Vec>) -> Result<(), String> { let op = DatabaseOperation::new(op_type, payload); match self.tx.send(op) { - Ok(_) => Ok("OK".to_string()), - Err(e) => Err(anyhow!("Failed to send to channel: {e}")), + Ok(_) => Ok(()), + Err(e) => Err(format!("Failed to send to channel: {e}").to_string()), } }