Clean up error propagation

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-02-08 18:13:52 +00:00
parent 52e88f4bc9
commit 76bf2fddcb
24 changed files with 465 additions and 325 deletions

View File

@@ -221,7 +221,7 @@ async fn handle_websocket_message(
}
struct BarsHandler {
app_config: Arc<Config>,
config: Arc<Config>,
}
#[async_trait]
@@ -286,7 +286,10 @@ impl Handler for BarsHandler {
| websocket::incoming::Message::UpdatedBar(message) => {
let bar = Bar::from(message);
debug!("Received bar for {}: {}.", bar.symbol, bar.time);
database::bars::upsert(&self.app_config.clickhouse_client, &bar).await;
database::bars::upsert(&self.config.clickhouse_client, &bar)
.await
.unwrap();
}
websocket::incoming::Message::Success(_) => {}
websocket::incoming::Message::Error(message) => {
@@ -298,7 +301,7 @@ impl Handler for BarsHandler {
}
struct NewsHandler {
app_config: Arc<Config>,
config: Arc<Config>,
}
#[async_trait]
@@ -373,7 +376,7 @@ impl Handler for NewsHandler {
let input = format!("{}\n\n{}", news.headline, news.content);
let sequence_classifier = self.app_config.sequence_classifier.lock().await;
let sequence_classifier = self.config.sequence_classifier.lock().await;
let prediction = block_in_place(|| {
sequence_classifier
.predict(vec![input.as_str()])
@@ -388,7 +391,10 @@ impl Handler for NewsHandler {
confidence: prediction.confidence,
..news
};
database::news::upsert(&self.app_config.clickhouse_client, &news).await;
database::news::upsert(&self.config.clickhouse_client, &news)
.await
.unwrap();
}
websocket::incoming::Message::Success(_) => {}
websocket::incoming::Message::Error(message) => {
@@ -401,9 +407,9 @@ impl Handler for NewsHandler {
}
}
pub fn create_handler(thread_type: ThreadType, app_config: Arc<Config>) -> Box<dyn Handler> {
pub fn create_handler(thread_type: ThreadType, config: Arc<Config>) -> Box<dyn Handler> {
match thread_type {
ThreadType::Bars(_) => Box::new(BarsHandler { app_config }),
ThreadType::News => Box::new(NewsHandler { app_config }),
ThreadType::Bars(_) => Box::new(BarsHandler { config }),
ThreadType::News => Box::new(NewsHandler { config }),
}
}