refactor: single object queue

This commit is contained in:
Per Stark
2024-09-30 11:54:43 +02:00
parent 827fefad06
commit f3ad3e1893
10 changed files with 488 additions and 135 deletions

View File

@@ -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()
}
}