mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-28 02:19:34 +02:00
refactor: replace Box<dyn Error> with anyhow::Result
- ingestion_pipeline::run_worker_loop returns anyhow::Result<()> - api_router::ApiState::new returns anyhow::Result<Self> - html_router::HtmlState::new_with_resources is infallible, returns Self - main/server/worker binary entry points return anyhow::Result<()>
This commit is contained in:
@@ -16,7 +16,7 @@ impl ApiState {
|
|||||||
pub async fn new(
|
pub async fn new(
|
||||||
config: &AppConfig,
|
config: &AppConfig,
|
||||||
storage: StorageManager,
|
storage: StorageManager,
|
||||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
) -> anyhow::Result<Self> {
|
||||||
let surreal_db_client = Arc::new(
|
let surreal_db_client = Arc::new(
|
||||||
SurrealDbClient::new(
|
SurrealDbClient::new(
|
||||||
&config.surrealdb_address,
|
&config.surrealdb_address,
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ impl HtmlState {
|
|||||||
reranker_pool: Option<Arc<RerankerPool>>,
|
reranker_pool: Option<Arc<RerankerPool>>,
|
||||||
embedding_provider: Arc<EmbeddingProvider>,
|
embedding_provider: Arc<EmbeddingProvider>,
|
||||||
template_engine: Option<Arc<TemplateEngine>>,
|
template_engine: Option<Arc<TemplateEngine>>,
|
||||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
) -> Self {
|
||||||
let templates =
|
let templates =
|
||||||
template_engine.unwrap_or_else(|| Arc::new(create_template_engine!("templates")));
|
template_engine.unwrap_or_else(|| Arc::new(create_template_engine!("templates")));
|
||||||
debug!("Template engine configured for html_router.");
|
debug!("Template engine configured for html_router.");
|
||||||
|
|
||||||
Ok(Self {
|
Self {
|
||||||
db,
|
db,
|
||||||
openai_client,
|
openai_client,
|
||||||
session_store,
|
session_store,
|
||||||
@@ -65,7 +65,7 @@ impl HtmlState {
|
|||||||
embedding_provider,
|
embedding_provider,
|
||||||
conversation_archive_cache: Arc::new(RwLock::new(HashMap::new())),
|
conversation_archive_cache: Arc::new(RwLock::new(HashMap::new())),
|
||||||
conversation_archive_cache_writes: Arc::new(AtomicUsize::new(0)),
|
conversation_archive_cache_writes: Arc::new(AtomicUsize::new(0)),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieval_strategy(&self) -> RetrievalStrategy {
|
pub fn retrieval_strategy(&self) -> RetrievalStrategy {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use uuid::Uuid;
|
|||||||
pub async fn run_worker_loop(
|
pub async fn run_worker_loop(
|
||||||
db: Arc<SurrealDbClient>,
|
db: Arc<SurrealDbClient>,
|
||||||
ingestion_pipeline: Arc<IngestionPipeline>,
|
ingestion_pipeline: Arc<IngestionPipeline>,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> anyhow::Result<()> {
|
||||||
let worker_id = format!("ingestion-worker-{}", Uuid::new_v4());
|
let worker_id = format!("ingestion-worker-{}", Uuid::new_v4());
|
||||||
let lease_duration = Duration::from_secs(DEFAULT_LEASE_SECS as u64);
|
let lease_duration = Duration::from_secs(DEFAULT_LEASE_SECS as u64);
|
||||||
let idle_backoff = Duration::from_millis(500);
|
let idle_backoff = Duration::from_millis(500);
|
||||||
|
|||||||
+3
-4
@@ -22,7 +22,7 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
|||||||
use tokio::task::LocalSet;
|
use tokio::task::LocalSet;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
// Set up tracing
|
// Set up tracing
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(fmt::layer().with_writer(std::io::stderr))
|
.with(fmt::layer().with_writer(std::io::stderr))
|
||||||
@@ -118,7 +118,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
embedding_provider.clone(),
|
embedding_provider.clone(),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await;
|
||||||
|
|
||||||
let api_state = ApiState::new(&config, storage.clone()).await?;
|
let api_state = ApiState::new(&config, storage.clone()).await?;
|
||||||
|
|
||||||
@@ -295,8 +295,7 @@ mod tests {
|
|||||||
embedding_provider,
|
embedding_provider,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await;
|
||||||
.expect("failed to build html state");
|
|
||||||
|
|
||||||
let api_state = ApiState {
|
let api_state = ApiState {
|
||||||
db: db.clone(),
|
db: db.clone(),
|
||||||
|
|||||||
+2
-2
@@ -12,7 +12,7 @@ use tracing::info;
|
|||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
|
|
||||||
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
// Set up tracing
|
// Set up tracing
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(fmt::layer().with_writer(std::io::stderr))
|
.with(fmt::layer().with_writer(std::io::stderr))
|
||||||
@@ -73,7 +73,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
embedding_provider,
|
embedding_provider,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await;
|
||||||
|
|
||||||
let api_state = ApiState::new(&config, storage).await?;
|
let api_state = ApiState::new(&config, storage).await?;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ use tracing::info;
|
|||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
// Set up tracing
|
// Set up tracing
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(fmt::layer())
|
.with(fmt::layer())
|
||||||
|
|||||||
Reference in New Issue
Block a user