feat: Implement NATS-based event processing for note smart features and add Qdrant collection auto-creation.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use futures_util::StreamExt;
|
||||
use notes_domain::services::SmartNoteService;
|
||||
use notes_infra::{
|
||||
DatabaseConfig,
|
||||
@@ -10,8 +11,18 @@ use crate::config::Config;
|
||||
|
||||
mod config;
|
||||
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| "notes_worker=info,notes_infra=info".into()),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
let config = Config::from_env();
|
||||
let nats_client = async_nats::connect(&config.broker_url).await?;
|
||||
let db_config = DatabaseConfig::new(config.database_url.clone());
|
||||
@@ -29,8 +40,27 @@ async fn main() -> anyhow::Result<()> {
|
||||
config.embedding_provider
|
||||
);
|
||||
|
||||
// subscribe to jobs and process them
|
||||
// (Future: consume NATS messages and call smart_service.process_note(¬e))
|
||||
// Subscribe to note update events
|
||||
let mut subscriber = nats_client.subscribe("notes.updated").await?;
|
||||
tracing::info!("Worker listening on 'notes.updated'...");
|
||||
|
||||
while let Some(msg) = subscriber.next().await {
|
||||
// Parse message payload (assuming the payload IS the Note JSON)
|
||||
let note_result: Result<notes_domain::Note, _> = serde_json::from_slice(&msg.payload);
|
||||
|
||||
match note_result {
|
||||
Ok(note) => {
|
||||
tracing::info!("Processing smart features for note: {}", note.id);
|
||||
match smart_service.process_note(¬e).await {
|
||||
Ok(_) => tracing::info!("Successfully processed note {}", note.id),
|
||||
Err(e) => tracing::error!("Failed to process note {}: {}", note.id, e),
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to deserialize note from message: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user