mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-28 20:31:53 +01:00
refactor: single object queue
This commit is contained in:
@@ -1,34 +1,42 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
|
||||
use tracing::{error, info};
|
||||
|
||||
use crate::{models::ingress::{IngressContent, IngressInput}, rabbitmq::publisher::RabbitMQProducer, redis::client::RedisClient};
|
||||
use crate::{models::ingress_content::{create_ingress_objects, IngressInput}, rabbitmq::publisher::RabbitMQProducer, redis::client::RedisClient};
|
||||
|
||||
pub async fn ingress_handler(
|
||||
Extension(producer): Extension<Arc<RabbitMQProducer>>,
|
||||
Json(input): Json<IngressInput>,
|
||||
) -> impl IntoResponse {
|
||||
info!("Recieved input: {:?}", input);
|
||||
info!("Received input: {:?}", input);
|
||||
|
||||
let redis_client = RedisClient::new("redis://127.0.0.1/");
|
||||
if let Ok(content) = IngressContent::new(input, &redis_client).await {
|
||||
|
||||
// Publish content to RabbitMQ (or other system)
|
||||
match producer.publish(&content).await {
|
||||
Ok(_) => {
|
||||
info!("Message published successfully");
|
||||
"Successfully processed".to_string().into_response()
|
||||
match create_ingress_objects(input, &redis_client).await {
|
||||
Ok(objects) => {
|
||||
for object in objects {
|
||||
match producer.publish(&object).await {
|
||||
Ok(_) => {
|
||||
info!("Message published successfully");
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to publish message: {:?}", e);
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Failed to publish message",
|
||||
)
|
||||
.into_response();
|
||||
}
|
||||
}
|
||||
}
|
||||
StatusCode::OK.into_response()
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to publish message: {:?}", e);
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "Failed to publish message").into_response()
|
||||
error!("Failed to process input: {:?}", e);
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Failed to process input",
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
error!("Failed to create IngressContent object" );
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "Failed to create object").into_response()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user