Skip to content

Commit

Permalink
Refine RedisCacheDatabase scaffolding in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Nov 26, 2023
1 parent c125557 commit 9952e3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion nautilus_core/infrastructure/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait CacheDatabase {

fn new(trader_id: TraderId, config: HashMap<String, Value>) -> Result<Self::DatabaseType>;
fn read(&mut self, op_type: String) -> Result<Vec<Vec<u8>>>;
fn write(&mut self, op_type: String, payload: Vec<Vec<u8>>) -> Result<String>;
fn write(&mut self, op_type: String, payload: Vec<Vec<u8>>) -> Result<(), String>;
fn handle_ops(
trader_id: TraderId,
config: HashMap<String, Value>,
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/infrastructure/src/python/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ impl RedisCacheDatabase {
#[pyo3(name = "read")]
fn py_read(&mut self, op_type: String) -> PyResult<Vec<Vec<u8>>> {
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<Vec<u8>>) -> PyResult<String> {
fn py_write(&mut self, op_type: String, payload: Vec<Vec<u8>>) -> PyResult<()> {
match self.write(op_type, payload) {
Ok(ok) => Ok(ok),
Ok(_) => Ok(()),
Err(e) => Err(to_pyvalue_err(e)),
}
}
Expand Down
8 changes: 4 additions & 4 deletions nautilus_core/infrastructure/src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -64,11 +64,11 @@ impl CacheDatabase for RedisCacheDatabase {
Ok(result)
}

fn write(&mut self, op_type: String, payload: Vec<Vec<u8>>) -> Result<String> {
fn write(&mut self, op_type: String, payload: Vec<Vec<u8>>) -> 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()),
}
}

Expand Down

0 comments on commit 9952e3a

Please sign in to comment.