feat: arc client

This commit is contained in:
Per Stark
2025-01-15 08:12:08 +01:00
parent 972919a515
commit 2e70bd0636
2 changed files with 10 additions and 15 deletions

View File

@@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
&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

View File

@@ -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<SurrealDbClient>,
openai_client: async_openai::Client<async_openai::config::OpenAIConfig>,
}
impl ContentProcessor {
pub async fn new(app_config: &AppConfig) -> Result<Self, AppError> {
pub async fn new(surreal_db_client: Arc<SurrealDbClient>) -> Result<Self, AppError> {
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(),
})
}