From 2e70bd06369b275bad45b4223ea50934a4db5355 Mon Sep 17 00:00:00 2001 From: Per Stark Date: Wed, 15 Jan 2025 08:12:08 +0100 Subject: [PATCH] feat: arc client --- src/bin/worker.rs | 8 +++++--- src/ingress/content_processor.rs | 17 +++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/bin/worker.rs b/src/bin/worker.rs index f648626..2098829 100644 --- a/src/bin/worker.rs +++ b/src/bin/worker.rs @@ -27,7 +27,7 @@ async fn main() -> Result<(), Box> { let config = get_config()?; - let job_queue = JobQueue::new(Arc::new( + let surreal_db_client = Arc::new( SurrealDbClient::new( &config.surrealdb_address, &config.surrealdb_username, @@ -36,9 +36,11 @@ async fn main() -> Result<(), Box> { &config.surrealdb_database, ) .await?, - )); + ); - let content_processor = ContentProcessor::new(&config).await?; + let job_queue = JobQueue::new(surreal_db_client.clone()); + + let content_processor = ContentProcessor::new(surreal_db_client).await?; loop { // First, check for any unfinished jobs diff --git a/src/ingress/content_processor.rs b/src/ingress/content_processor.rs index e6a5fd6..fbc746f 100644 --- a/src/ingress/content_processor.rs +++ b/src/ingress/content_processor.rs @@ -1,4 +1,4 @@ -use std::time::Instant; +use std::{sync::Arc, time::Instant}; use text_splitter::TextSplitter; use tracing::{debug, info}; @@ -12,7 +12,7 @@ use crate::{ text_chunk::TextChunk, text_content::TextContent, }, }, - utils::{config::AppConfig, embedding::generate_embedding}, + utils::embedding::generate_embedding, }; use super::analysis::{ @@ -20,21 +20,14 @@ use super::analysis::{ }; pub struct ContentProcessor { - db_client: SurrealDbClient, + db_client: Arc, openai_client: async_openai::Client, } impl ContentProcessor { - pub async fn new(app_config: &AppConfig) -> Result { + pub async fn new(surreal_db_client: Arc) -> Result { Ok(Self { - db_client: SurrealDbClient::new( - &app_config.surrealdb_address, - &app_config.surrealdb_username, - &app_config.surrealdb_password, - &app_config.surrealdb_namespace, - &app_config.surrealdb_database, - ) - .await?, + db_client: surreal_db_client, openai_client: async_openai::Client::new(), }) }